Zawsze się z tym mylę, więc oto przypadek testowy przypomnienia; powiedzmy, że mamy ten bashskrypt do przetestowania 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
W tym momencie zmiana nie jest przenoszona do pamięci podręcznej, podobnie jak 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")
Jeśli od tego momentu to zrobimy git checkout, wynik będzie następujący:
$ git checkout HEAD -- b.txt
$ git status
On branch master
nothing to commit, working directory clean
Jeśli zamiast tego zrobimy git reset, wynik będzie:
$ 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")
Tak więc w tym przypadku - jeśli zmiany nie są wprowadzane, nie git resetma znaczenia, a zmiany są git checkoutzastępowane.
Powiedzmy teraz, że ostatnia zmiana z powyższego skryptu jest przenoszona / buforowana, to znaczy, że zrobiliśmy to również git add b.txtna końcu.
W tym przypadku git statusw tym momencie jest:
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: b.txt
Jeśli od tego momentu to zrobimy git checkout, wynik będzie następujący:
$ git checkout HEAD -- b.txt
$ git status
On branch master
nothing to commit, working directory clean
Jeśli zamiast tego zrobimy git reset, wynik będzie:
$ 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")
Tak więc w tym przypadku - jeśli zmiany są wprowadzane etapowo, git resetzasadniczo zmieniają zmiany etapowe w zmiany niestacjonarne - jednocześnie git checkoutcałkowicie je nadpisując.