Enter git reflog to save the day

So, i had to stop and delete a branch i'd been working on, I figured out a better way to build it, sure it meant throwing that code away but it made sense.
There were only 2 commits on this branch and neither would be needed, or so i thought.

Simple, I can run git checkout develop and git branch -d dead-feature, of course git warns me about this, but the branches content is no longer needed so replace that -d with -D and its all ok.
But wait... there was a migration on that branch... and its been run on my development system.
The migration file is now gone, entire branch gone in fact, and my database is now wrong without a simple way to rollback.

Enter git reflog to save the day. Running git reflog i found the commit in which i created the file, in my case its hash was 1f6a6e4.

Now I just needed to save that file, so with a little help from git show i can output that raw file:
git show 1f6a6e4:application/migrations/2014_01_22_173120_create_blah_blah_table.php > application/migrations/2014_01_22_173120_create_blah_blah_table.phpFinally all that's left is to rollback that last migration, remove that temp file and continue on to build the new feature.

comments powered by Disqus
Want to setup your own server? Digital Ocean offer $100 free for new accounts.
DigitalOcean Referral Badge