2

I want git to never have a conflict on this file:
test/file.txt
when merging. I tried the following in .gitattributes test/file.txt merge=theirs

but I need to define the theirs merge strategy. I saw online that I can define the ours strategy by executing this:
git config --global merge.theirs.driver true
which sets the driver to true (bash true) which will keep the local file instead of the new one.
I want to do the opposite. How can I define the theirs driver to get the new copy and discard the local one when merging (after a git pull)?

Jad Joubran
  • 2,511
  • 3
  • 31
  • 57

1 Answers1

4

How can I define the theirs driver to get the new copy and discard the local one when merging (after a git pull)?

As I mentioned in "How do I tell git to always select my local version for conflicted merges on a specific file?", you would need to call a script like:

git config merge.keepTheir.name "always keep their during merge"
git config merge.keepTheir.driver "keepTheir.sh %O %A %B"

With keepTheir.sh (put anywhere in your PATH)

cp -f $3 $2
exit 0

Or, as jthill suggests below in the comments, directly:

git config merge.keepTheir.driver "cp -f %B %A"

Plus, as noted by Tal Jacob - Sir Jacques in the comments:

after you have configured the 'keepTheir' driver in the config file, you should navigate to your .gitattributes file and add the line:

test/file.txt merge=keepTheir
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Why not skip the external script and define the driver as `"mv %B %A"`? – jthill Jan 19 '15 at 19:51
  • @jthill sure, that is just how I implemented it at the time 6 years ago in http://stackoverflow.com/a/930495/6309 (mainly for testing) – VonC Jan 19 '15 at 19:52
  • Note that after you have configured the 'keepTheir' driver in the config file, you should navigate to your `.gitattributes` file and add the line `test/file.txt merge=keepTheir` – Tal Jacob - Sir Jacques Apr 03 '22 at 09:45
  • 1
    @TalJacob-SirJacques Good point, thank you. I have included your comment in the answer for more visibility. – VonC Apr 03 '22 at 13:48