How to go back to a specific commit?

git reset YOURSHA

To go back to a specific commit use git reset YOURSHA.

The reset command resets your current HEAD to a specific commit, without creating a new commit for the revert.

You need to replace YOURSHA with the SHA of the commit you want to revert to. You can find the SHA with git log.

With no additional flags the reverted changes are kept.

Layer 1
Terminal Example
git status
On branch main
nothing to commit, working tree clean
git log --oneline
4392049 (HEAD -> main) Adding README.md
192da0f Adding image.png
9cfff18 Adding file.txt
git reset 9cfff18

git status
On branch main
Untracked files:
  (use "git add ..." to include in what will be committed)
    README.md
    image.png

nothing added to commit but untracked files present (use "git add" to track)

See git reset to learn more about it.

Last modified on November 30, 2021.

You might also like