Sławosz
Sławosz

Reputation: 11687

Automatically resolve conflict on git for given file

I have database schema file in repo with always changes. Is there a possiblity to fix conflicts with ours or theirs strategy on merge automatically?

Upvotes: 1

Views: 245

Answers (2)

Ash Wilson
Ash Wilson

Reputation: 24478

Define a custom merge driver by adding a stanza like the following to your .git/config:

[merge "ours"]
  name = Always take our version
  driver = echo
[merge "theirs"]
  name = Always take their version
  driver = cat %B > %A

The merge driver accepts a number of parameters -- %A is "our" version of the file and %B is "their" version -- and is expected to leave the result of the merge in %A. Hence, the "our" merge driver does nothing, while the "theirs" merge driver can just copy %B over %A.

Now, tell git to use either the ours or theirs merge strategy for your file with a .gitattributes file:

db/schema.rb merge=theirs

# Or:

db/schema.rb merge=ours

Upvotes: 3

zegarmistrz
zegarmistrz

Reputation: 1

You can add this file to .gitignore

Upvotes: 0

Related Questions