Git颜色合并/重新基准冲突



我想知道是否有人在发生冲突时给合并或重基础的输出着色。我想特别用文件名给这行上色,例如这里的第二行:

Auto-merging CMakeLists.txt
CONFLICT (content): Merge conflict in CMakeLists.txt
Failed to merge in the changes.

感谢

编辑:

使用git别名和bash函数,我可以编写以下内容:

color-merge = "!f() { git merge --no-commit --stat $1| egrep --color 'CONFLICT .*|$'; }; f"

这将给所有冲突线上色,但:

  • 无法更改传递给合并的选项
  • 要跟踪的分支上没有完成

所以我在寻找更强大的东西。

干杯

另一个选项可能是创建一个git别名。这对我来说更可取,因为它将特定于git的自定义保持在一起,而不是浮动在某个不相关的.profile文件中的其他位置。

~/.gitconfig或本地git项目的.git/config中添加这样的内容也应该有效:

[alias]
    color-merge = "!f() { git merge $@ | egrep --color 'CONFLICT .*|$' ; }; f"

调用方式如下:git color-merge branch --option1

请注意,shell的GREP_COLOR环境变量将控制所使用的颜色。

这是一个从新问题中引用的旧问题,也是第一个出现在我的谷歌搜索结果上的问题,所以我认为5年后发布更新的答案很方便:

只需将行unmerged = <color>添加到git设置文件(~/.gitconfig)中的[color "status"]组中,如下所示:

[color "status"]
     unmerged  = yellow

我使用的是git --version2.11.0。所以是的,最后git支持它:-)

[color]
  branch = auto
  diff = auto
  status = auto
[color "branch"]
  current = yellow reverse
  local = yellow
  remote = green
[color "diff"]
  meta = yellow bold
  frag = magenta bold
  old = red bold
  new = green bold
[color "status"]
  added = yellow
  changed = green
  untracked = cyan
http://jblevins.org/log/git-colors

所以合并冲突恐怕没有颜色。

这里有一个bash函数,它可以让您到达那里(除了分支完成):

   git-merge-color () { git merge  $@ | egrep --color 'CONFLICT .*|$'; }

您可以使用任何"git merge"参数调用git merge-color。

最新更新