2

I switched to a older commit with: git checkout $HASH to look for something i did in an older version of my directory. Now i want to go back to the newest commit, but i cant find the Hash for that anymore? when i do a git log it just shows the older commits from the commit i am currently at. How can i switch to the newest commit again?

Zoe stands with Ukraine
  • 25,310
  • 18
  • 114
  • 149
w1ng
  • 314
  • 1
  • 2
  • 11
  • Possible duplicate of [Is there any way to git checkout previous branch?](https://stackoverflow.com/questions/7206801/is-there-any-way-to-git-checkout-previous-branch) – sashoalm Nov 10 '17 at 15:56

2 Answers2

3

git checkout <branch>, e.g. git checkout master.

Fred Foo
  • 342,876
  • 71
  • 713
  • 819
2

Use the name of the branch on which you worked before

git checkout [branch]

If for some reason you don't know the name, you can find the previous position in the reflog

git reflog

It gives you a list of commits on which you worked in the past, where the first position is the most recent one.

Adam Byrtek
  • 11,653
  • 2
  • 31
  • 30
  • Also: `git checkout -`, which is short for `git checkout @{-1}`. The `@{-N}` syntax means “Nth most-recent checkout”. – Chris Johnsen Apr 23 '11 at 11:54