Banner_top
Site_activities_1024x330


Recovering lost local git commits


Fri Nov 16th 2012

I accidentally reset a local branch to the remote using 'git reset --hard origin/master'. I thought I had previously pushed my local changes.

Luckily git never throws away changes, it only changes the HEAD. To recover lost local commits:

1) View the local changes to HEAD with 'git reflog'. In my case the log looked like this and commit bab3332 was the one I wanted to recover. (1.5 hrs of work)

1908cc8 HEAD@{10}: reset: moving to origin/master
bab3332 HEAD@{11}: commit: add exemption attributes to offerings and add them to form
1908cc8 HEAD@{12}: commit: tests pass with bundle exec rake
20d8946 HEAD@{13}: commit: fix haml

2) cherry-pick the commits you want back: 'git cherry-pick bab3332'

3) Run your tests and push your changes to master.

4) git rules!

 


More Blogs

Recovering lost local git commits

A New Client: Thomas Hinds Tobacconist

The Choice Matrix - Official Launch!

A New Client: Manitoba Health

Manitoba Venture Challenge