Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to do with commit made in a detached head

Using git I made something like this

git clone git checkout {a rev number tree rev before} (here I started to be in a detached head state) //hacking git commit //hacking git commit (some commit where made on origin/master) git pull (which does complete because there was some error due to the fact that I'm no more on master) 

Because it said to me that I can still commit when in a detached head state, I did so. But now I want to like merge my detached head branch and my local master branch, and then push my bunch of changes to origin/master.

So my question is how could I merge the master branch with my actual state (detached head)

like image 788
benzen Avatar asked Aug 19 '11 16:08

benzen


People also ask

What happens if you commit on a detached head?

If you want to discard the changes in the detached HEAD state, you only need to check out to the existing or previous branch. The commits on the detached HEAD state will not affect your existing branch, and Git will archive them.

How do I fix a detached committed head?

If you want to keep changes made with a detached HEAD, just create a new branch and switch to it. You can create it right after arriving at a detached HEAD or after creating one or more commits. The result is the same. The only restriction is that you should do it before returning to your normal branch.

How do you commit and push in a detached head?

Detached head usually means that the branch you checkout to does not has the latest commit. So, basically you need to adjust the HEAD of your current branch to the latest commit. There are usually 2 ways to do it. You can create a new branch, push your code to that branch (this will pull your detached code too).

How do I merge a detached head into a master?

To get master branch updated with your committed changes, make a temporary branch where you are (this way the temporary branch will have all the committed changes you have made in the detached HEAD) , then switch to the master branch and merge the temporary branch with the master.


1 Answers

Create a branch where you are, then switch to master and merge it:

git branch my-temporary-work git checkout master git merge my-temporary-work 
like image 145
Ryan Stewart Avatar answered Oct 28 '22 19:10

Ryan Stewart