How to go back to a specific commit and discard the changes?
git reset --hard YOURSHA
To go back to a specific commit and discard the changes use
git reset --hard YOURSHA.
The reset command resets your current HEAD to a specific commit, without creating a new commit for the revert.
The --hard flag discards your reverted changes.
You need to replace YOURSHA with the SHA of the commit you want to revert to. You can find the SHA with
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 --hard 9cfff18
HEAD is now at 9cfff18 Adding file.txt
See git reset to learn more about it.