Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix git "not currently on any branch" after merge conflicts

Tags:

git

I tried to commit the changes. After a lot of problems and conflicts, I managed to resolved every problem. However, the code I committed is not currently on any branch (as the git status shows). How can I fix this problem? I tried several solutions but none worked for me. I tried the command git merge but it says it's already up to date.

Update

The result of git log --all --graph --oneline --decorate is:

* 7833c31 (HEAD) Changed LI tool
* c205a25 Fixed merge conflicts
*   7b10e48 (vsproj/master, master) 4-7-2013
|\  
| * cc51cb0 3/9/2013
| * 62ea718 Updated mail and added barcode
| * 9a3573a 1-7-2013
| * 96ded0e Updated ExamsPrinter
| * be6638a 12-25-2012
| * 89cba4b Added HTML to PDF and updated Email app
| * fa96aeb Updates
| * 9ffcfcc Changes in CloudDownloader, LinkedIn & Twitter apps
| * 609c555 Added README file
| * bf8a344 Started implementing CloudDownloader, created FileDownloader, updated FacebookInfoBot
| * c3556ce First Commit
* 3a59cd5 4-7-2013
like image 393
Alireza Noori Avatar asked Apr 07 '13 13:04

Alireza Noori


2 Answers

Not sure what happened, but you could fix it easily by creating a new branch and then merging it:

git branch lost_changes
git checkout master
git merge lost_changes
like image 148
kan Avatar answered Sep 28 '22 16:09

kan


So you can see on your history what's going on here. You did a merge, producing

*   7b10e48 (vsproj/master, master) 4-7-2013

and then after explicitly disconnecting your checkout from the master branch tip%1 you committed

* c205a25 Fixed merge conflicts

and

* 7833c31 (HEAD) Changed LI tool

So to just make your current checkout the master branch tip you do

git checkout -B master HEAD

and that looks like the simplest recovery here.

Why did you explicitly commit merge conflicts? You have to tell git you've resolved them all (by git adding the correct content) before it will accept the commit.

%1: the usual way I get a no-ref "detached" checkout is git checkout HEAD@{1}, there are lots of ways, git's fairly casual about branch tips and so will you be after you get comfortable with what's going on here.

like image 43
jthill Avatar answered Sep 28 '22 15:09

jthill