Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git color merge/rebase conflicts

Tags:

git

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 :

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

like image 807
Pluc Avatar asked Mar 13 '12 14:03

Pluc


People also ask

Why do I get conflicts when rebasing?

Handling Conflicts When Rebasing When applying commits to a new base state, it is possible that the new base has made changes that are conflicting with the changes you are trying to apply. For example, if on main someone edited the same file and line you did on your branch. The same thing happens when merging.


1 Answers

Another option might be to create a git alias. This is preferable to me because it keeps keep git-specific customizations together instead of floating elsewhere in an unrelated .profile file somewhere.

Adding something like this to your ~/.gitconfig or the local git project's .git/config should also work:

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

Invoke it like so: git color-merge branch --option1

Note that your shell's GREP_COLOR environment variable will control the color used.

like image 76
beporter Avatar answered Sep 19 '22 15:09

beporter