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?
-
Possible duplicate of Is there any way to git checkout previous branch?sashoalm– sashoalm2017-11-10 15:56:26 +00:00Commented Nov 10, 2017 at 15:56
Add a comment
|
2 Answers
git checkout <branch>, e.g. git checkout master.
2 Comments
Adam Byrtek
git checkout HEAD won't work, the head is already detached.Fred Foo
@Adam: you're right, deleted that. My testing was sloppy, apparently.
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.
1 Comment
Chris Johnsen
Also:
git checkout -, which is short for git checkout @{-1}. The @{-N} syntax means “Nth most-recent checkout”.