Not currently on any branch + git commit + checkout when not in any branch. Did i loose my changes?

Sewdn picture Sewdn · May 18, 2011 · Viewed 25.7k times · Source

I was not currently on any branch when I commited my changes. I didn't really notice the message and checked out another branch.

How can I retrieve my changes? I can't merge or checkout, since there is no branch to merge from.

Answer

manojlds picture manojlds · May 18, 2011

You can use git reflog to get the commit hash of the commit that you did while in "no branch" ( a detached HEAD) and merge that in to the branch that you are currently in ( master maybe)

Something like git merge HEAD@{1}

You can also git rebase -i and "pick" the commit you want from the reflog.