Changing git conflict markers

Spread the love

Question Description

Is it possible to change the conflict markers to something user defined?


It has happened several times to me that, due to hasty and not very careful merging of several branches, there are some left over merge tags in my LaTeX document. With most programming projects these tags would result in an syntax error and therefore I would spot them. However, in Latex the <<<<, ==== and >>>> tags are just compiled into some other character sequences without any warning.

To remedy this I would like to change these conflict markers into something that doesn’t compile, or at leasts make them very obvious to spot (e.g. page breaks, huge font warnings, or compile warnings).

I could of course make a (bash) script that replaces all those markers by something of my choice, but I would prefer it a more elegant solution to this problem.

P.S. I’ve found the merge.conflictstyle option, but the diff3 option only adds the |||| marker which also compiles without warning.

Practice As Follows

Even if there were a way to make custom conflict markers LaTeX specific (I don’t think there is but I could very well be wrong), it might be tough to pick one that worked in all cases. An easier solution would be enabling git’s stock “pre-commit” hook, which identifies conflict markers at commit time and rejects the commit if they’re present. To enable it:

mv .git/hooks/pre-commit.sample .git/hooks/pre-commit

The stock hook that ships with git also looks for whitespace errors. To run the check manually, use this command:

git diff --check

You may be interested in these books.

Pro Git
(paid link)

As an Amazon Associate I earn from qualifying purchases.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.