更改git冲突标记 [英] Changing git conflict markers

查看:158
本文介绍了更改git冲突标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将冲突标记更改为用户定义的标记?

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

动机:

我经历了好几次,由于仓促而又不是很仔细地合并多个分支,LaTeX文档中有一些合并标记.在大多数编程项目中,这些标签会导致语法错误,因此我会发现它们.但是,在Latex中,<<< ;、 ====和>>>>标签只是被编译成其他字符序列而没有任何警告.

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).

我当然可以制作一个(bash)脚本,以我选择的方式替换所有这些标记,但是我希望它是解决此问题的更优雅的方法.

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.我找到了merge.conflictstyle选项,但diff3选项仅添加||||.标记也会在没有警告的情况下进行编译.

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

推荐答案

即使有某种方法可以使LaTeX特定于自定义冲突标记(我不认为有,但我很可能错了),这可能是很难选择在所有情况下都有效的产品.一个更简单的解决方案是启用git的股票预提交"挂钩,该挂钩可在提交时识别冲突标记,并在存在冲突时拒绝提交.要启用它:

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

git附带的股票挂钩也查找空白错误.要手动运行检查,请使用以下命令:

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

git diff --check

这篇关于更改git冲突标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆