2

I am using git to track a large LaTeX document which I write using Kile on different machines.

Kile writes to its .kilepr config file when closing Kile. The problem I often run into is that I commit before closing Kile. So I commit and push, work on the other machine, and when I come back and want to pull I get a merge conflict because the .kilepr file contains the cursor position (which obviously changed now).

My question: Is there a way to add a merge rule to git config for a specific file (always use --theirs)? Using .gitignore is not an option since the .kilepr file contains important information such as files in the project.

user334287
  • 211
  • 1
  • 9

2 Answers2

2

All possible ways to simulate a merge -s theirs are listed in "git command for making one branch like another".

But for one file, all you need is a merge driver, declared in a .gitattributes file, with a keepTheir script like:

mv -f $3 $2
exit 0

See "git merge -s theirs” needed — but I know it doesn't exist" for a concrete example of a custom merge driver (including my own version).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @user334287 sure it will work: it is executed by the msys bash included with msysgit. – VonC Aug 31 '12 at 17:12
1

2018 solution: Merge Drivers

In git config you can add custom merge drivers:

[merge "my-custom-driver"]
    name = A custom merge driver used to resolve conflicts in certain files
    driver = my-merge-tool.sh %O %A %B

but you can also just return 'true' for the driver which will always keep local changes:

[merge "keep-local-changes"]
    name = A custom merge driver which always keeps the local changes
    driver = true

Then in .gitattributes you can define which file types use which custom merge drivers:

/folder/**/*.fileExtension merge=keep-local-changes
Geordie
  • 1,920
  • 2
  • 24
  • 34