0

I've just performed this action: git checkout SHA to look at the code of a past commit. I would now like to go back to how I had before (I presume this means go back to the HEAD) and carry on. How can I do this?

I tried git log to get the SHA for my most recent commit but it's not there..

tonitone120
  • 1,920
  • 3
  • 8
  • 25

1 Answers1

0

After checkout, your HEAD is changed to the hash of the commit you selected. (The name HEAD refers to the most recent thing you checked out.) To change back to your main branch, use:

git checkout main

Use a different branch name if you want to switch back to a different branch.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • Much appreciated. I now see this has been asked here too: https://stackoverflow.com/questions/2427288/how-to-get-back-to-the-latest-commit-after-checking-out-a-previous-commit – tonitone120 Jan 02 '21 at 23:52
  • Thanks, I've added a duplicate link so other people can find the answer more quickly. – Greg Hewgill Jan 03 '21 at 00:01