I’d like to see the file from a specific commit in the past, I’m thinking of git reset --hard but I won’t be able to see the commits beyond that commit. How do I go back to a commit (together with the state of the files), have a look at the files, the go to the present again?
I’d like to see the file from a specific commit in the past, I’m
Share
Suppose your current branch is
masterand the old commit isa1b2c3, then you can change all the files in your working tree back to the old commit with:… and return to
masterwith:This way of hopping about in your git history (i.e. checking out a commit with its object name, also known as its hash or SHA1sum) is very useful for finding a previous good commit for
git bisect, for example, since it won’t move your branches.One thing to bear in mind is that you’ll get a possibly confusing warning when doing this: if you check out a commit from its object name (
a1b2c3) that will put you into a state known as “detached HEAD”, whereHEAD, which usually represents your current branch, instead points directly to a particular commit. This isn’t something to worry about – it’s very useful for moving about in your history – but it does mean that if you create new commits whenHEADis detached, they won’t move a branch forward.fork0 points out in the comment below the potentially useful shortcut
git checkout -, which will checkout the previous branch or commit thatHEADpointed at.