Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The shortest possible output from git log containing author and date

How can I show a git log output with (at least) this information:

* author * commit date * change 

I want it compressed to one line per log entry. What's the shortest possible format for that?

(tried --format=oneline but that does not show the date)

like image 463
Jesper Rønn-Jensen Avatar asked Sep 17 '09 19:09

Jesper Rønn-Jensen


People also ask

How do I limit a git log?

The most basic filtering option for git log is to limit the number of commits that are displayed. When you're only interested in the last few commits, this saves you the trouble of viewing all the commits in a page. You can limit git log 's output by including the - option.

What is git author date?

In Git, the author date is when someone first creates a commit with git commit . The commit date is identical to the author date unless someone changes the commit date by using git commit --amend , a force push, a rebase, or other Git commands.

What is git log -- Oneline?

Git Log OnelineThe 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 is the order of git log?

By default, with no arguments, git log lists the commits made in that repository in reverse chronological order; that is, the most recent commits show up first. As you can see, this command lists each commit with its SHA-1 checksum, the author's name and email, the date written, and the commit message.


2 Answers

git log --pretty=format:"%h%x09%an%x09%ad%x09%s"

did the job. This outputs:

  fbc3503 mads    Thu Dec 4 07:43:27 2008 +0000   show mobile if phone is null...      ec36490 jesper  Wed Nov 26 05:41:37 2008 +0000  Cleanup after [942]: Using timezon   ae62afd tobias  Tue Nov 25 21:42:55 2008 +0000  Fixed #67 by adding time zone supp   164be7e mads    Tue Nov 25 19:56:43 2008 +0000  fixed tests, and a 'unending appoi   93f1526 jesper  Tue Nov 25 09:45:56 2008 +0000  adding time.ZONE.now as time zone    2f0f8c1 tobias  Tue Nov 25 03:07:02 2008 +0000  Timezone configured in environment   a33c1dc jesper  Tue Nov 25 01:26:18 2008 +0000  updated to most recent will_pagina 

Inspired by stackoverflow question: "git log output like svn ls -v", i found out that I could add the exact params I needed.

To shorten the date (not showing the time) use --date=short

In case you were curious what the different options were:
%h = abbreviated commit hash
%x09 = tab (character for code 9)
%an = author name
%ad = author date (format respects --date= option)
%s = subject
From kernel.org/pub/software/scm/git/docs/git-log.html (PRETTY FORMATS section) by comment of Vivek.

like image 159
Jesper Rønn-Jensen Avatar answered Sep 28 '22 05:09

Jesper Rønn-Jensen


I use these two .gitconfig settings:

[log]   date = relative [format]   pretty = format:%h %Cblue%ad%Creset %ae %Cgreen%s%Creset 

%ad is the author date, which can be overidden by --date or the option specified in the [log] stanza in .gitconfig. I like the relative date because it gives an immediate feeling of when stuff was comitted. Output looks like this:

6c3e1a2 2 hours ago [email protected] lsof is a dependency now. 0754f18 11 hours ago [email protected] Properly unmount, so detaching works. 336a3ac 13 hours ago [email protected] Show ami registration command if auto register fails be2ad45 17 hours ago [email protected] Fixes #6. Sao Paolo region is included as well. 5aed68e 17 hours ago [email protected] Shorten while loops 

This is all of course in color, so it is easy to distinguish the various parts of a log line. Also it is the default when typing git log because of the [format] section.

2014 UPDATE: Since git now supports padding I have a nice amendment to the version above:

pretty = format:%C(yellow)%h %Cblue%>(12)%ad %Cgreen%<(7)%aN%Cred%d %Creset%s 

This right aligns the relative dates and left aligns committer names, meaning you get a column-like look that is easy on the eyes.

Screenshot

  ss#1

2016 UPDATE: Since GPG commit signing is becoming a thing, I thought I'd update this post with a version that includes signature verification (in the screenshot it's the magenta letter right after the commit). A short explanation of the flag:

%G?: show "G" for a good (valid) signature, "B" for a bad signature, "U" for a good signature with unknown validity and "N" for no signature

Other changes include:

  • colors are now removed if the output is to something other than the tty (which is useful for grepping etc.)
  • git log -g now contains the reflog selector.
  • Save 2 parens on refnames and put them at the end (to preserve column alignment)
  • Truncate relative dates if they are too long (e.g. 3 years, 4..)
  • Truncate commiter names (might be a little short for some ppl, just change the %<(7,trunc) or check out the git .mailmap feature to shorten commiter names)

Here's the config:

pretty = format:%C(auto,yellow)%h%C(auto,magenta)% G? %C(auto,blue)%>(12,trunc)%ad %C(auto,green)%<(7,trunc)%aN%C(auto,reset)%s%C(auto,red)% gD% D 

All in all column alignment is now preserved a lot better at the expense of some (hopefully) useless characters. Feel free to edit if you have any improvements, I'd love to make the message color depend on whether a commit is signed, but it doesn't seem like that is possible atm.

Screenshot

Screenshot of git log

like image 45
andsens Avatar answered Sep 28 '22 04:09

andsens