Her zaman bununla kafam karışıyor, işte bir hatırlatma testi örneği; diyelim ki bashtest etmek için şu komut dosyasına sahibiz git:
set -x
rm -rf test
mkdir test
cd test
git init
git config user.name test
git config user.email test@test.com
echo 1 > a.txt
echo 1 > b.txt
git add *
git commit -m "initial commit"
echo 2 >> b.txt
git add b.txt
git commit -m "second commit"
echo 3 >> b.txt
Bu noktada, değişiklik önbellekte gösterilmez, yani git status:
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: b.txt
no changes added to commit (use "git add" and/or "git commit -a")
Bu noktadan itibaren yaparsak git checkout, sonuç şudur:
$ git checkout HEAD -- b.txt
$ git status
On branch master
nothing to commit, working directory clean
Bunun yerine git reset, sonuç:
$ git reset HEAD -- b.txt
Unstaged changes after reset:
M b.txt
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: b.txt
no changes added to commit (use "git add" and/or "git commit -a")
Yani, bu durumda - değişiklikler sahnelenmezse, değişikliklerin üzerine git resetyazarken fark etmez git checkout.
Şimdi, yukarıdaki komut dosyasındaki son değişikliğin sahnelendiğini / önbelleğe alındığını, yani aynı zamanda git add b.txt yani sonunda varsayalım.
Bu durumda, git statusbu noktada:
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: b.txt
Bu noktadan itibaren yaparsak git checkout, sonuç şudur:
$ git checkout HEAD -- b.txt
$ git status
On branch master
nothing to commit, working directory clean
Bunun yerine git reset, sonuç:
$ git reset HEAD -- b.txt
Unstaged changes after reset:
M b.txt
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: b.txt
no changes added to commit (use "git add" and/or "git commit -a")
Dolayısıyla, bu durumda - değişiklikler aşamalı ise git reset, temel olarak işaretlenmemiş değişikliklere aşamalı değişiklikler yapar - ancak git checkoutdeğişikliklerin tamamen üzerine yazılır.