Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitx How do I get my 'Detached HEAD' commits back into master [duplicate]

People also ask

How do you reattach a detached head?

You must understand that any of your branches will not be affected if you ever get into a detached state. Now, the best way to reattach the HEAD is to create a new branch. We can do it as simple as git checkout -b <branch-name> . This will commit the changes from your temporary branch into the branch you need them.

How do I fix the detached head on origin master?

All you have to do is 'git checkout [branch-name]' where [branch-name] is the name of the original branch from which you got into a detached head state. The (detached from asdfasdf) will disappear. Show activity on this post. And head is re attached!

Can you merge a detached head?

You can commit into this branch just like any other branch. Once you are done committing, you want to push it to the remote. Now you can push it to remote like any other branch. Of course, I merged it later to master .


If checkout master was the last thing you did, then the reflog entry HEAD@{1} will contain your commits (otherwise use git reflog or git log -p to find them). Use git merge HEAD@{1} to fast forward them into master.

EDIT:

As noted in the comments, Git Ready has a great article on this.

git reflog and git reflog --all will give you the commit hashes of the mis-placed commits.

Git Ready: Reflog, Your Safety Net

Source: http://gitready.com/intermediate/2009/02/09/reflog-your-safety-net.html


If your detached HEAD is a fast forward of master and you just want the commits upstream, you can

git push origin HEAD:master

to push directly, or

git checkout master && git merge [ref of HEAD]

will merge it back into your local master.