简体   繁体   English

Git颜色合并/ rebase冲突

[英]Git color merge/rebase conflicts

I was wondering if someone had a trick to color the ouput of a merge or rebase when there is a conflict. 我想知道是否有人在发生冲突时为合并或变换的输出着色。 I want to color specially the line with the filename, for example the second line here : 我想特别为带有文件名的行着色,例如第二行:

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

Thanks 谢谢

EDIT : 编辑:

Using git alias and a bash function I can write this : 使用git别名和bash函数我可以这样写:

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

This will color all the conflict lines but : 这将为所有冲突线着色,但是:

  • It's impossible to change the options passed to merge 改变传递给合并的选项是不可能的
  • There is no completion on the branch to be tracked 要跟踪的分支机构没有完成

So I'm looking for something more powerful. 所以我正在寻找更强大的东西。

Cheers 干杯

Another option might be to create a git alias . 另一种选择可能是创建一个git别名 This is preferable to me because it keeps keep git-specific customizations together instead of floating elsewhere in an unrelated .profile file somewhere. 这对我来说是优选的,因为它保持一致的git特定的自定义,而不是漂浮在某个不相关的.profile文件的其他地方。

Adding something like this to your ~/.gitconfig or the local git project's .git/config should also work: 将这样的内容添加到~/.gitconfig或本地git项目的.git/config也应该有效:

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

Invoke it like so: git color-merge branch --option1 像这样调用它: git color-merge branch --option1

Note that your shell's GREP_COLOR environment variable will control the color used. 请注意,shell的GREP_COLOR环境变量将控制使用的颜色。

This is an old question referenced from newer questions, and it's the first one that appears on my Google search results, so I think it's convenient to post the updated answer 5 years later: 这是一个从较新问题引用的旧问题,它是我的Google搜索结果中出现的第一个问题,所以我认为5年后发布更新的答案很方便:

Just add the line unmerged = <color> into [color "status"] group in your git settings file ( ~/.gitconfig ), like this: 只需在你的git设置文件( ~/.gitconfig~/.gitconfig unmerged = <color>行添加到[color "status"]组中,如下所示:

[color "status"]
     unmerged  = yellow

I'm using git --version 2.11.0 . 我正在使用git --version 2.11.0 So yeah, finally git supported it :-) 所以是的,最后git支持它:-)

Here is a bash function that gets you there (except for branch completion): 这是一个bash函数,可以帮助您(分支完成除外):

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

You can invoke git-merge-color with any 'git merge' arguments that you please. 您可以使用任何'git merge'参数调用git-merge-color。

[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

So no colors for a merge conflict I'm afraid. 所以没有合并冲突的颜色我害怕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM