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?
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.
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.
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 ' .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With