A basic Git merge driver for Rails' db/schema.rb top-version conflicts.
This is inspired by this gist, and slightly improved upon.
- Grab the merge driver file and save it someplace. This is a Ruby script intended to run in POSIX environments that support hashbang syntaxes and the
/usr/bin/env
command. In particular, this will not work straight from Cmd or Powershell as-is. - Make it executable (e.g.
chmod a+x merge-db-schemas-top-version
). - In a relevant Git attributes file (e.g.
$HOME/.config/git/attributes
or your project's.git/attributes
), add the following:
db/schema.rb merge=railsschema
- In a relevant Git config file (e.g.
$HOME/.gitconfig
or your project's.git/config
), add the following:
[merge "railsschema"]
name = Rails schema.db merge driver
driver = "path/to/the/file" %O %A %B %L %P
(For instance, if you saved the merge driver in /home/tdd/perso/bin
, this would read driver = /home/tdd/perso/bin/merge-db-schemas-top-version %O %A %B %L %P
).
There! Now you should benefit from this merging for merges and rebases. It likely b0rks on stash applies, tho. Contributions welcome!