This question already has an answer here:
If I am going to use checkout to find bugs in my code, I think it would be helpful to be able to checkout the previous commit without having to lookup its ID with
git log. Or more efficient at least.
Best How To :
Yep, git provides two nice ways to do this:
HEAD~1 (HEAD is your current commit). The number of carets following
HEAD or the number after the tilda determine how many commits back you are referring to.
So for instance
HEAD~3 both refer to three commits back.
To checkout the previous commit, it's just
git checkout HEAD^
To checkout the previous commit relative to a specific branch's commit, say
develop, it's just
git checkout develop^