Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Move head one commit ahead

Tags:

git

I did a git reset HEAD~1 to go back one commit. I did this a number of times.

I now want to go back to where HEAD was originally but am not sure how to move my HEAD forward.

Does anyone know what command I need to use?

1-2-3-4-5-6

Originally I was at 6 and I reset back to 3. I now want to go back to 5. My understanding is that since I did not do git reset --hard my original files from commit 6 is still available. Theoretically I should be able to un-reset and move back up correct?

like image 835
SeekingAlpha Avatar asked Jan 14 '14 02:01

SeekingAlpha


People also ask

How do I move the head to the latest commit?

We need to specify the HEAD or the relative reference of the head to the commit we want to move. We do this using git reset –hard HEAD^ which means resetting back to the commit before head, and git reset –hard HEAD~n, which means resetting back to the n commits before head.

How do I move between commits?

To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.

How do I go backwards in git?

Use git checkout & the ID (in the same way you would checkout a branch) to go back: $ git checkout <commit-id> . Don't forget the final ' .


1 Answers

use git reflog to see SHA-1 of last operations and then do git reset --hard <sha1>.

Git keeps objects (and their SHA-1 respectively) even they go "out of scope" until next git gc invocation. So if you think, you've lost something in the project history, use git reflog to see if that smth is there.

like image 171
user3159253 Avatar answered Sep 18 '22 10:09

user3159253