Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to truncate field in git log --pretty

Tags:

git

We have some people with long names in our git commit logs. Currently, my format is

pretty = %C(yellow)%h%Creset %s %C(red)(%an, %cr)%Creset

which shows

276840c Kyle Heironimus Added updated hello world example. (3 months ago)

I really just want

276840c Kyle Added updated hello world example. (3 months ago)

If I can't just take the first word of the author name, the first 5 characters would be my second choice.

Any way to do this?

like image 703
Kyle Heironimus Avatar asked Oct 14 '11 18:10

Kyle Heironimus


People also ask

How do I make my git log pretty?

A simple fix is to pass the --pretty=oneline parameter, which makes it all fit on a single line. It's taking up less space, but missing crucial information like the date of the commit. There are longer versions of that same --pretty parameter. In fact, it allows you to specify all the fields you want in the output.

What is pretty format git?

Pretty-print the contents of the commit logs in a given format, where <format> can be one of oneline, short, medium, full, fuller, reference, email, raw, format:<string> and tformat:<string>.

What is the output of the code git log pretty Oneline?

Git Log Oneline The oneline option is used to display the output as one commit per line. It also shows the output in brief like the first seven characters of the commit SHA and the commit message. It will be used as follows: $ git log --oneline.

What does -- decorate command do?

The --decorate flag makes git log display all of the references (e.g., branches, tags, etc) that point to each commit. This lets you know that the top commit is also checked out (denoted by HEAD ) and that it is also the tip of the main branch.


1 Answers

If you use %aN rather than %an, Git will consider aliases listed in ~/.mailmap when displaying author names. If you create that file, and add, say -

Kyle <[email protected]>

then you should get the desired output.

like image 187
Jonathan del Strother Avatar answered Sep 21 '22 17:09

Jonathan del Strother