5

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
Community
  • 1
  • 1
Alireza Noori
  • 14,961
  • 30
  • 95
  • 179
  • You may need to explain how you got into merge conflict: `merge`, `pull`, `rebase`, `stash pop`, etc. It looks like you are in the middle of a rebase. – Bert F Apr 07 '13 at 13:34
  • please list the commands you ran – Chronial Apr 07 '13 at 13:41
  • Well, I really don't know all the commands I ran. I just panicked, searched the web and ran a bunch of commands. I remember using `merge` and `pull` but I've not used `rebase` and `stash pop`. At first a lot of files got marked for conflict with `<<< – Alireza Noori Apr 07 '13 at 14:01
  • Post the results of `git log --all --graph --oneline --decorate`. – jthill Apr 07 '13 at 15:20
  • maybe this is helpful: http://stackoverflow.com/questions/6048425/not-currently-on-any-branch-git-commit-checkout-when-not-in-any-branch-did – niculare Apr 07 '13 at 15:21
  • If you dont remember the commands, at least show us the log for your current state, and the log of the branch you were on. For ease of reading i suggest using the log command like this: `git log -5 --oneline HEAD` and `git log -5 --oneline ` – eddiemoya Apr 07 '13 at 16:47
  • @jthill Thanks for the command. Posted the update. – Alireza Noori Apr 07 '13 at 21:35
  • If you're on a Linux system, the `history` command is useful to find out what happened while you panicked. Also, `git reflog` might refresh your memory. When it comes to "not on a branch", this (typically) means that you're in the middle of an operation. `git --continue` is often the right option. – HonkyTonk Apr 07 '13 at 22:14

3 Answers3

10

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
kan
  • 28,279
  • 7
  • 71
  • 101
2

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.

jthill
  • 55,082
  • 5
  • 77
  • 137
0

If you truly aren't on a branch, the simple solution is to create a new branch as such:

git branch <name> 7833c31

or

git branch <name> HEAD

and the you can go about figuring out the problem or, hopefully, just continuting your development.

GoZoner
  • 67,920
  • 20
  • 95
  • 145