Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color merge commits differently in Git log output?

Tags:

git

I currently format my Git log using the following pretty definition:

[format]
  pretty = format:%C(normal)%h %C(blue)%s %C(yellow)[%an]%C(reset)

This results in the output below:

enter image description here

Most of the time, I don't need to pay much attention to merge commits, so I have an alias that includes the --no-merges flag by default:

enter image description here

I would actually prefer for merge commit log entries to always be present but be colored differently from non-merge commit log entries (so I can train my eye to skip them by default).

Is it possible to color merge commit log entries differently from non-merge commit log entries? If so, how do I achieve that?

like image 623
stkent Avatar asked Oct 19 '25 12:10

stkent


1 Answers

You can achieve this with a git alias, using eg. sed.

[alias]
    logo = "!logo(){ git log --pretty='format:<<%p>>%H %s %D' $@ | sed -e 's/<<[^ ]* [^ ]*\\( [^ ]*\\)*>>/\\x1B[36m/' -e 's/<<[^ ]*>>//' -e 's/$/\\x1B[0m/' | less -FRSX;  }; logo"

The %p specifier prints all the parents of the commit. The sed patterns recognize when there is more than one parent and replace that case with a color code. The color is reset at the end of each line.

The function wrapper and less give you the capability to pass git log parameters and restore paging, respectively.

like image 144
Mitten.O Avatar answered Oct 21 '25 01:10

Mitten.O



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!