Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to dynamically generate git log format?

Tags:

git

git-log

I'd like to always show Author Name and Author Date, but optionally show Committer Name and Committer Date if they are different from Author Name and Date.

This is mainly for use after a rebase. The Author info remains the same, but the Committer info changes. If and only if they are different, I'd like to show the Committer info in addition to the Author info.

Author and Committer info are the same:

%C(yellow)%h%Creset %s %C(cyan)(%an - %ar)%Creset

Different:

%C(yellow)%h%Creset %s %C(cyan)(%an - %ar, %cn - %cr)%Creset

Is this possible?

like image 795
Earle Clubb Avatar asked Feb 22 '26 09:02

Earle Clubb


1 Answers

There are no conditionals in the format arguments, and no format string that expands conditionally like that, so: no. On the other hand, you could extract the information from a commit manually (in a script), compare, and then choose which format to apply to that one commit, so: yes, if you're willing to do this outside of the git log command.

For showing a single commit, the latter seems reasonable. For looking at the whole log, I suspect it would be very painful. :-) (Could still be done, use git rev-list to generate the list of revs, then git log each, one at a time, piping the whole result through the same pager git log would use, etc. But... painful.)

like image 68
torek Avatar answered Feb 24 '26 21:02

torek