是否可以轻松更改Git中的默认冲突标记? [英] Is it possible to easily change the default conflict markers in Git?

查看:151
本文介绍了是否可以轻松更改Git中的默认冲突标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Git中,是否可以将默认冲突标记更改为其他内容?

默认情况下,它们如下所示:

 < <<<<<<<<<<<<<<<<<<<< HEAD 

[有些代码]

|||||||合并后的共同祖先

[某些代码]

=======

[部分代码]

>>>>>>>一些提交消息

例如,我认为在C#文件中让它们以评论字元:

  //<<<<<<<< HEAD 

通过这种方式,冲突标记中的编译错误不会妨碍编译错误代码本身,而我正在解决合并。



有没有办法做到这一点?



不要给出你不应该这样做的答案。我已经知道这些后果,并且我对他们很满意。Git旨在提供灵活性。)

解决方案

这是我如何做到这一点,如果我做到了(谨慎行事):

添加一个预编译步骤你的项目(从你的配置文件我假设你正在使用C#)来运行sed(假设你安装了git,bash命令可用于任何事情)。如果发现了冲突标记,请在sed中插入'//'标记。



为什么这是一个糟糕的主意:



我不会推荐这个,因为这个效果不会给你带来任何好处。当有一个未解决的冲突得到保存,增加和承诺的时候,你就要失败壮观。做你在这里提出的是要求麻烦。如果成功,请谨慎行事。



希望这有助于您。


In Git, is it possible to change the default conflict markers to something else?

By default they look like this:

<<<<<<< HEAD

    [some code]

||||||| merged common ancestors

    [some code]

=======

    [some code]

>>>>>>> some commit message

For instance, I was thinking it might be nice in C# files to have them start with comment characters:

// <<<<<<< HEAD

That way compile errors from the conflict markers wouldn't get in the way of compile errors from the code itself while I'm resolving a merge.

Is there a way to do this?

(Please don't give an answer that says "You shouldn't do this." I already know the ramifications, and I'm OK with them. Git is designed for flexibility.)

解决方案

Here is how I would do it IF I HAD TO (proceed with caution):

add a precompile step in your projects (from your profile I assume you are using C#) to run sed (assuming you installed git with the bash commands available to everything). Have sed insert '//' markers where ever a conflict marker is found.

Why this is a bad idea:

I would not recommend this as the effect wouldn't give you any gain. You WANT to fail spectacularly when there is an unresolved conflict that was saved, added and committed. Doing what you are proposing here is asking for trouble. If you succeed, proceed with caution.

Hope this helps.

这篇关于是否可以轻松更改Git中的默认冲突标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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