Changing git conflict markers

2020-07-08 07:22发布

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

Motivation:

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.

2条回答
爷的心禁止访问
2楼-- · 2020-07-08 08:00

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:

cd <repo>
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
查看更多
ゆ 、 Hurt°
3楼-- · 2020-07-08 08:20

Maybe you can change the attribute conflict-marker-size with a big number. By big number, I mean a number that would trigger a Latex warning because the line is too long.

$ cat .gitattributes
*.tex conflict-marker-size=100 ;# Or whatever makes Latex unhappy
查看更多
登录 后发表回答