Better git log formatting control

I have a log git alias like this

log --graph --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %ci %an - %s'' 

production

 * 123456 2013-03-01 09:45:11 +0100 Name Surname - commit message 1 * 123457 2013-03-01 09:45:11 +0100 Name LongerSurname - commit message 2 * 123458 2013-03-01 09:45:11 +0100 Name Sho - commit message 3 

I would like to get a different format, namely

 * 123456 2013-03-01 09:45:11 Name Surname - commit message 1 * 123457 2013-03-01 09:45:11 Name LongerS - commit message 2 * 123458 2013-03-01 09:45:11 Name Sho - commit message 3 

Note that iso8601 does not have the GMT + 1 specification, and how long names are abbreviated and short names are padded to align the log message.

Is it possible to do this with a regular git log? if not, what is the best way to achieve it?

+4
source share
1 answer

You can use ANSI escape codes to move the cursor. You will also need to configure the pager settings.

 export LESS+=' -r' # Make sure your pager will accept ANSI escape codes git log --graph \ --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %ci %x1b[s%an%x1b[u%x1b[3C - %s' 

Used escape codes:

  • % x1b [s - keep current cursor position
  • % x1b [u - restore the cursor position, i.e. move the cursor to where it was when you used% x1b [s
  • % x1b [3C - move the cursor forward 3 positions (you can change the number according to the number of characters you want to display).

After moving the cursor using these escape characters, the following text will overwrite the final part of the author’s name, providing the desired effect.

Regarding the date, see the link in the comments: How to change the git log date formats

+4
source

All Articles