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.
Asked
Active
Viewed 68 times
0
juil
- 2,408
- 3
- 18
- 18
2 Answers
2
Yep, git provides two nice ways to do this: HEAD^ or 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^^^ or 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^
lemonhead
- 5,328
- 1
- 13
- 25
0
There are several ways to refer to commits. The full SHA is the most direct one. For your purposes, HEAD^ should work.
Noufal Ibrahim
- 71,383
- 13
- 135
- 169