Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking out an old commit and maintaining the head on the master branch?

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?

like image 474
devoured elysium Avatar asked Apr 14 '11 03:04

devoured elysium


People also ask

How do you checkout a previous commit in a 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.

What does checking out a commit mean?

"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.


1 Answers

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

like image 90
Nick Canzoneri Avatar answered Sep 29 '22 08:09

Nick Canzoneri