Search code examples
gitcommit

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


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.


Solution

  • 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.