Skip to content

Instantly share code, notes, and snippets.

mberrueta / bin-squash_migrations
Created May 10, 2018 — forked from bf4/bin-squash_migrations
Squash Rails migrations in this one easy step
View bin-squash_migrations
#!/usr/bin/env bash
git ls-files db/migrate/*.rb | sort | tail -1 | \
ruby -e "[/\d+/]; init_schema=%(db/migrate/#{schema_version}_init_schema.rb);
%x(git rm -f db/migrate/*.rb;
mkdir db/migrate;
git mv db/schema.rb #{init_schema};
rake db:migrate;
git add db/schema.rb; git commit -m 'Squashed migrations')"
mberrueta /
Created Sep 21, 2017 — forked from jbgo/
How to recover a git branch you accidentally deleted

UPDATE: A better way! (August 2015)

As pointed out by @johntyree in the comments, using git reflog is easier and more reliable. Thanks for the suggestion!

 $ git reflog
1ed7510 HEAD@{1}: checkout: moving from develop to 1ed7510
3970d09 HEAD@{2}: checkout: moving from b-fix-build to develop
1ed7510 HEAD@{3}: commit: got everything working the way I want
70b3696 HEAD@{4}: commit: upgrade rails, do some refactoring
You can’t perform that action at this time.