Currently for switching to another git commit (on the same branch...actually, on the master branch!), I'm executing the command
git checkout ea3d5ed039edd6d4a07cc41bd09eb58edd1f2b3a
Now, every time I do this git tells me that I'm now with a detached head. How do I go to an older commit and still maintain the head on the same branch?
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.
"To check out" means that you take any given commit from the repository and re-create the state of the associated file and directory tree in the working directory. When you check out a commit that is not a branch head (e.g. git checkout HEAD~2 ), you are on a so-called detached head.
Most of the time when I do this I checkout to a temp branch:
git checkout -b temp-branch-name ea3d5ed039edd6d4a07cc41bd09eb58edd1f2b3a
Then after I'm done i just delete the branch
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