Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Automatically resolve Git merge conflicts in Rails schema.rb by picking the most recent date in the conflict (now works with Rails 5 and recent versions of Git). The following files should be in your home ~ directory. Inspired by
db/schema.rb merge=railsschema
attributesfile = /Users/your_user/.gitattributes
[merge "railsschema"]
name = newer Rails schema version
driver = "ruby -e '\n\
system %(git), %(merge-file), %(--marker-size=%L), %(%A), %(%O), %(%B)\n\
b =\n\
b.sub!(/^<+ .*\\nActiveRecord::Schema\\.define.version: ([0-9_]+). do\\n=+\\nActiveRecord::Schema\\.define.version: ([0-9_]+). do\\n>+ .*/) do\n\
%(ActiveRecord::Schema.define(version: #{[$1, $2].max}) do)\n\
end\n\, %(w)) {|f| f.write(b)}\n\
exit 1 if b.include?(%(<)*%L)'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment