Skip to content

Instantly share code, notes, and snippets.

@bobmaerten
Forked from jeromedalbert/.gitattributes
Last active August 3, 2024 03:02
Show Gist options
  • Save bobmaerten/efa460e038418479359f45877d6501fc to your computer and use it in GitHub Desktop.
Save bobmaerten/efa460e038418479359f45877d6501fc to your computer and use it in GitHub Desktop.
Automatically resolve Git merge conflicts in Rails schema.rb by picking the most recent date in the conflict (works with Rails 6 and recent versions of Git). The following files should be in your home ~ directory.
db/schema.rb merge=railsschema
[merge "railsschema"]
name = Newer Rails schema version
driver = "ruby -e '\n\
system %(git), %(merge-file), %(--marker-size=%L), %(%A), %(%O), %(%B)\n\
b = File.read(%(%A))\n\
b.sub!(\\A<+ .*\\nActiveRecord::Schema.define.version: ([_0-9]+). do\\n\\|+ .*\\nActiveRecord::Schema.define.version: ([_0-9]+). do\\n=+\\nActiveRecord::Schema.define.version: ([_0-9]+). do\\n>+ .*\\z) do\n\
%(ActiveRecord::Schema.define(version: #{[$1, $2, $3].max}) do)\n\
end\n\
File.open(%(%A), %(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