Oliver Hausler Oliver Hausler -4 years ago 244
Git Question

Easy way to keep using current HEAD in Git?

I have the following situation in Git: I did a lot of refactoring and detached the head because I went back and forth between versions a few times. Because of the detached head I am no longer able to commit to the origin/master remote branch.

branches

The HEAD is my version that I want to keep. What I tried is merging the origin/master remote branch into HEAD so I can commit that version back. During the merge I said I want to keep my own changes wherever there were conflicts.

The result was a mess with a lot of missing files. Luckily I made a file copy before the operation so I could go back to the situation that I just described.

Now I am stuck. I don't want to go through each and every change and decide what I want to keep (there are many). I only want to commit the lost HEAD back to origin/master, including the new directory structure. Any easy way to do that?

--

After I ran through the steps recommended by @Martin my status is now these (see comment as well):

new status

Answer Source

You can checkout master and merge your HEAD. I'm naming it good_stuff below to avoid ever having to know the sha-1...

(assuming everything is already committed on your current HEAD)

git checkout -b good_stuff HEAD
git checkout master
git merge good_stuff

solve conflicts

git commit
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download