When I do git checkout -, git checks out the last branch I had checked out. Where is that information stored?
Asked
Active
Viewed 127 times
7
Ram Rachum
- 84,019
- 84
- 236
- 374
-
This might be helpful: http://stackoverflow.com/questions/7206801/is-there-any-way-to-git-checkout-previous-branch – Sergio Tulentsev Sep 13 '16 at 08:53
1 Answers
4
It scans .git/logs/HEAD (the reflog for HEAD) for the last line looking like :
checkout: moving from <branchA> to <branchB>
the "last branch" is branchA
As said in the post linked by @SergioTulentsev :
git checkout -is a shorthand forgit checkout @{-1}.
@{-1}is thebranchAof the lastcheckout: ...line@{-2}is thebranchAof the previous to lastcheckout: ...line- etc ...