git reset vs revert vs restore
19 May 2024I forgot the git command to restore a single file to a specific commit, modifying the working directory. It’s git restore
. But I need to remember the difference between git restore
, git reset
, and git revert
….
The Github Documentation Page
The github /git
documentation page says this:
git-revert
is about making a new commit that reverts the changes made by other commits.git-restore
is about restoring files in the working tree from either the index or another commit. This command does not update your branch. The command can also be used to restore files in the index from another commit.git-reset
is about updating your branch, moving the tip in order to add or remove commits from the branch. This operation changes the commit history.
Nate should revisit this post to clarify:
revert
vsrestore
specifically- the documentation for
git revert
says (emphasis added): -
If you want to extract specific files as they were in another commit, you should see
git-restore
, specifically the –source option.
- the documentation for
- and use a single hypothetical developer/codebase that demonstrates all three commands with three different scenarios
checkout
vs restore
Some confusion about checkout
vs restore
.
Seems like restore
and switch
are subsets of checkout
functionality.
- So if my question is:
revert
vsrestore
vsreset
- And
restore
is related tocheckout
- Then a similar question is , the difference between
revert
vscheckout
vsreset
Other helpful links