1

I have some stuff I have been working on and I have managed to get the 'head detached at commit' error. I need to put the commit back on the master branch as I have no other copy of my work and I cant risk losing it.... Really scared to lose my work.

Thanks for any help.

1

1 Answer 1

2

First: add a branch at your current commit, so you won't loose any code

git checkout -b save

Then: you need to merge this work with your master. You may be in one of these 2 situations (Check with gitk --all)

Case 1

A--B--C  master
    \
      D  save

Just rebase your work on master

git rebase master


A--B--C--D  master, save

Case 2

        master
       /
A--B--C--D save

You just have to move your master on save

git branch -f master
git checkout master

or

git checkout master
git merge save


           master
          /
A--B--C--D save
1
  • Thank you for this crystal-clear guide. Came in very handy for me today. I wonder why the asker never really came round to "accepting" it. Commented Jul 11, 2015 at 21:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.