git-checkout vs. git-reset vs. git-restore

This note compares the differences between the default actions of git-checkout, git-reset and git-restore.

git-checkout[1]

1
2
3
# restore hello.c from `HEAD` for both the index and the working tree
# equivalent to `git restore --staged --worktree hello.c`
git checkout hello.c

git-reset[2]

1
2
3
# restore hello.c from `HEAD` for the index
# equivalent to `git restore --staged hello.c`
git reset -- hello.c

git-restore[3]

1
2
# restore hello.c from the index for the working tree
git restore hello.c

  1. https://git-scm.com/docs/git-checkout ↩︎

  2. https://git-scm.com/docs/git-reset ↩︎

  3. https://git-scm.com/docs/git-restore ↩︎