Git - restore vs reset vs revert vs rebase
git restore
Everyone is saying is experimental command as it was established in August 2019. Whereas, git reset
is very old, dating back to 2005.
- Restore all files in the current directory:
git restore .
- Restore a staged (git add-ed) file:
git restore --staged yourfilename
- Restore both the index and the working tree (same as git checkout):
git restore --source=HEAD --staged --worktree yourfilename
git reset
A powerful command that resets the working directory to a specific commit. Updates the current branch and the commit history as well.
git reset --hard HEAD~1
to undo the last commit.git reset --hard <COMMIT_ID>
to undo changes until the specified commit.
As a rule of thumb, use git reset
for undoing uncommitted changes.
git revert
Similar to git reset though the only difference is that it creates a new commit for every revert operation.
git revert HEAD~1
to undo the last commit.git revert <COMMIT_ID>
to undo changes until the specified commit.
As a rule of thumb, use git revert
for undoing committed changes.