7

When I do git checkout -, git checks out the last branch I had checked out. Where is that information stored?

Ram Rachum
  • 84,019
  • 84
  • 236
  • 374

1 Answers1

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 for git checkout @{-1}.

  • @{-1} is the branchA of the last checkout: ... line
  • @{-2} is the branchA of the previous to last checkout: ... line
  • etc ...
Community
  • 1
  • 1
LeGEC
  • 46,477
  • 5
  • 57
  • 104