Whoops! Committed to a detached HEAD

We’re hunting for a commit that went astray. git reflog will give you a view on all the recent repo activity.

$ git reflog
682e773 HEAD@0: checkout: moving from e20bfa28073bab29f9b8586c8e0b52471794dd51 to master
e20bfa2 HEAD@1: commit: Added post processing for body web skins
682e773 HEAD@2: checkout: moving from master to 682e7735724c155547b1a839edb55480dd56f7bb
682e773 HEAD@3: clone: from https://bitbucket.org/daemonite/dae-project-daemon.git

In this example we accidentally switched to a detached HEAD post clone which can happen easily if you are working with submodules.

682e773 HEAD@2: checkout: moving from master to 682e7735724c155547b1a839edb55480dd56f7bb

And right before we switch back to the master branch we lost a commit.

e20bfa2 HEAD@1: commit: Added post processing for body web skins

To repair things, double check you are on the branch you want to merge into, in this case master.

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

The commit we need is e20bfa2 so we merge just that.

$ git merge e20bfa2
Updating 682e773..e20bfa2
Fast-forward
 webskin/dmNews/displayBody.cfm | 3 +--
 webskin/types/displayBody.cfm  | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

Rejoice.

h/t @charles Stackoverflow