819

How can I show a Git log output with (at least) the following information?

  • author
  • commit date
  • change

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

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

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
asked Sep 17, 2009 at 19:58
2

17 Answers 17

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

does 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

It was inspired by Stack Overflow question: "Git log output like 'svn ls -v'". I found out that I could add the exact parameters 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

It is from git-log(1) Manual Page (PRETTY FORMATS section) by the comment of Vivek.

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Sep 17, 2009 at 20:07
Sign up to request clarification or add additional context in comments.

24 Comments

... and it is also useful to add date=short like cdunn2001 suggests in another answer
My favorite (short) oneliner is now to swap date before author and use the short date: git log --pretty=format:"%h %ad%x09%an%x09%s" --date=short
Spice it up with color and also show refs: git log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=short
tabulator can fix date and author width with this: git log --pretty="%C(Yellow)%h %C(reset)%ad (%C(Green)%cr%C(reset)) %C(Cyan)%an%x09: %C(reset)%s" --date=format:%Y-%m-%d\ %H:%M:%S
Fixed width columns table: alias glop="git log --pretty=format:'%C(yellow)%h|%Cred%ad|%Cblue%an|%Cgreen%d %Creset%s' --date=short | column -ts'|' | less -r"
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)
|
292

I use these two .gitconfig file settings:

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

%ad is the author date, which can be overridden 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 committed. The 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.

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

Since GPG commit signing is becoming a thing, here is 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 two parentheses 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 committer names (it might be a little short for some people, but just change the %<(7,trunc) or check out the Git .mailmap feature to shorten committer names)

Here's the configuration:

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.

I'd love to make the message color depend on whether a commit is signed, but it doesn't seem like that is possible at the moment.

Screenshot

Screenshot of 'git log'

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Feb 27, 2012 at 10:34

9 Comments

You can shorten the lines even more by using a mailmap. I have abbreviated the names of colleagues at my workplace down to only their first name :-)
The --pretty format answers are good, and the tig answer gives interactivity with no required configuration, but this one is brilliant -- it gives the requested one-line output (with color to boot!) using the standard 'git log' command. Very nice.
When using --right-left, I don't get the > < marks anymore. Tried adding %m to the format, but then > appears every time, even for a normal git log. Any clues how to have marks behave normally with the format?
@TrầnViệtHoàng --oneline is just an alias for --pretty=oneline. format.pretty is the default pretty format, but there is no way to override format.oneline afaik. What I'd do is omit the pretty = shortlog line in the config and then make an alias for running git log --pretty=shortlog.
|
168

Feel free to use this one:

git log --pretty="%C(Yellow)%h %C(reset)%ad (%C(Green)%cr%C(reset))%x09 %C(Cyan)%an: %C(reset)%s" --date=short -7

Note the -7 at the end, to show only the last 7 entries.

Look:

enter image description here

answered Mar 28, 2018 at 12:36

6 Comments

--date=short can be added to make it shorter.
@Hannes, Where are the branch names?
@Pacerier git log always shows the history of the currently checked out branch.
Add %d to restore "ref names" like (HEAD -> master).
Why use reset instead of auto?
|
134

enter image description here The -10 at the end is to show the last 10 commits.

Use a predefined Git alias (hs - short for history):

git hs

It was created once by this command:

git config --global alias.hs "log --pretty='%C(yellow)%h %C(cyan)%cd %Cblue%aN%C(auto)%d %Creset%s' --graph --date=relative --date-order"

%h = abbreviated commit hash
%cd = committer date (format respects --date= option)
%aN = author name (respects .mailmap )
%d = ref names
%s = subject

P.S. Since Git v2.13.0, --decorate is enabled by default.

References:

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Jul 29, 2020 at 1:46

9 Comments

This was so helpful! Thanks! I like this adjustment: git log --pretty='%C(cyan)%ad %C(yellow)%h %C(cyan)%d %Creset%s' --date-order --graph --date=iso
I also like git log --pretty='%C(cyan)%ad %C(yellow)%h %C(cyan)%d %Creset%s %C(red)%aN' --date-order --graph --date=iso for when I care about author name.
@Ryan I very liked your last adjustment! do you know if it's possible to save the 6 characters wasted in each line on the timezone?
@elady See here.
Thanks @WenfangDu! this is working for me: git log --pretty='%C(cyan)%ad %C(yellow)%h %C(cyan)%d %Creset%s %C(red)%aN' --date-order --graph --date=format:%d/%m/%y\ %H:%M:%S
|
131

Use:

git log --pretty=format:"%H %an %ad"

Use --date= to set a date format:

git log --pretty=format:"%H %an %ad" --date=short
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Sep 17, 2009 at 20:03

4 Comments

Great! Next time I'll probably only use %h over %H as the hash is just nonsense for my human eyes:)
Cool! I was not aware of --date=short
Just throwing this out there (8 years late): the hash may look like nonsense, but it's a useful tool if you wanted to cherrypick or compare the commits. Often you list the hash not because it has meaning, but because it has use
@stevendesu I suspect the point @JesperRønn-Jensen was making is that the long hash (%H) is overly verbose compared to the short hash (%h). Note that the short hash can be used for anything the long hash can be used for (including e.g. cherrypicking/comparing), assuming no collisions in the short hash.
62

tig is a possible alternative to using the git log command, available on the major open source Unix-like distributions.

On Debian or Ubuntu, try installing and running as follows:

sudo apt-get install tig

For Mac users, Homebrew (executable brew) to the rescue:

brew install tig

(tig gets installed)

tig

(log is displayed in pager as follows, with the current commit's SHA-1 hash value displayed at the bottom)

2010年03月17日 01:07 ndesigner changes to sponsors list
2010年03月17日 00:19 rcoder Raise 404 when an invalid year is specified.
2010年03月17日 00:06 rcoder Sponsors page now shows sponsors' level.
-------------------------- skip some lines ---------------------------------
[main] 531f35e925f53adeb2146dcfc9c6a6ef24e93619 - commit 1 of 32 (100%)

Since Markdown doesn't support text coloring, imagine: column 1: blue; column 2: green; column 3: default text color. Last line, highlighted. Hit Q or q to exit.


tig justifies the columns without ragged edges, which an ASCII tab (%x09) doesn't guarantee.

For a short date format, hit Shift + D (note: just D opens a diff view.) Configure it permanently by adding show-date = short to ~/.tigrc; or in a [tig] section in file .git/configure or ~/.gitconfig.

To see an entire change:

  • hit Enter. A sub pane will open in the lower half of the window.
  • use K, J keys to scroll the change in the sub pane.
  • at the same time, use the up, down keys to move from commit to commit.

Since tig is separate from Git and apparently Unix-like specific, it probably requires Cygwin to install on Windows. But for Fedora, I believe the install commands are su, (enter root password), yum install tig. For FreeBSD, try % su, (enter root password), pkg_add -r tig.


By the way, tig is good for a lot more than a quick view of the log: Screenshots & Manual

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Jan 10, 2012 at 19:12

4 Comments

please provide full example. Writing tigin my console simply gives me an error -bash: tig: command not found
wow. this tool is fantastic, and surprisingly fast! brew install tig
if you use mac, brew install tig
on Windows, babun users can pact install tig
38

Use

git log --pretty=format:'%h %ad %s (%an)' --date=short

or

git log --pretty=format:'%h %ad %s | %an' --date=short

...riffing on cdunn2001's answer above: I'd lose the author's e=mail and include just the author's name, as per Jesper and knittl, but in keeping with cdunn2001's idea of maintaining output in columns of constant width for ease of reading (great idea!).

In lieu of a separate left-justified column for author name, however, I wrap that flag at the end of the command with a parentheses or offset it with a pipe. (It could really be any character that serves as a visual aid in reading the output...albeit might make sense to avoid back or forward slashes in order to reduce confusing the output with a directory or something.)

Sample output:

6fdd155 2015年08月10日 Fixes casting error in doSave | John Doe
c4f4032 2015年08月10日 Fix for IE save. Add help button. | Jane
29a24a6 2015年08月10日 Fixes bug in Course | Mac
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Nov 15, 2011 at 10:18

Comments

34

Use a predefined Git alias, i.e.:

git work

It was created once by this command:

git config --global alias.work 'log --pretty=format:"%h%x09%an%x09%ad%x09%s"'

See Git Basics: Git Aliases .

Or more colored with a graph:

git config --global alias.work 'log --pretty=format:"%C(yellow)%h %ar %C(auto)%d %Creset %s , %Cblue%cn" --graph --all'

Enter image description here

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Jun 29, 2017 at 12:54

1 Comment

one can have columns that line up and a graph stackoverflow.com/questions/46229359/…
8

Use:

git log --pretty=format:'%h %ad %s%x09%ae' --date=short

Result:

e17bae5 2011年09月30日 Integrate from development -> main [email protected]
eaead2c 2011年09月30日 More stuff that is not worth mentioning [email protected]
eb6a336 2011年09月22日 Merge branch 'freebase' into development [email protected]
Constant-width stuff is first. The least important part -- the email domain -- is last and easy to filter.
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Oct 20, 2011 at 17:47

Comments

4

To show the commits I have staged, that are ready to push, I do

git log remotes/trunk~4..HEAD --pretty=format:"%C(yellow)%h%C(white) %ad %aN%x09%d%x09%s" --date=short | awk -F'\t' '{gsub(/[, ]/,"",2ドル);gsub(/HEAD/, "033円[1;36mH033円[00m",2ドル);gsub(/master/, "033円[1;32mm033円[00m",2ドル);gsub(/trunk/, "033円[1;31mt033円[00m",2ドル);print 1ドル "\t" gensub(/([\(\)])/, "033円[0;33m\1円033円[00m","g",2ドル) 3ドル}' | less -eiFRXS

The output looks something like:

ef87da7 2013年01月17日 haslers (Hm)Fix NPE in Frobble
8f6d80f 2013年01月17日 haslers Refactor Frobble
815813b 2013年01月17日 haslers (t)Add Wibble to Frobble
3616373 2013年01月17日 haslers Add Foo to Frobble
3b5ccf0 2013年01月17日 haslers Add Bar to Frobble
a1db9ef 2013年01月17日 haslers Add Frobble Widget

Where the first column appears in yellow, and the 'H' 'm' and 't' in parentesis show the HEAD, master and trunk and appear in their usual "--decorate" colors

Here it is with line breaks so you can see what it's doing:

git log remotes/trunk~4..HEAD --date=short
 --pretty=format:"%C(yellow)%h%C(white) %ad %aN%x09%d%x09%s"
 | awk -F'\t' '{
 gsub(/[, ]/,"",2ドル);
 gsub(/HEAD/, "033円[1;36mH033円[00m",2ドル);
 gsub(/master/, "033円[1;32mm033円[00m",2ドル);
 gsub(/trunk/, "033円[1;31mt033円[00m",2ドル);
 print 1ドル "\t" gensub(/([\(\)])/, "033円[0;33m\1円033円[00m","g",2ドル) 3ドル}'

I have aliased to "staged" with:

git config alias.staged '!git log remotes/trunk~4..HEAD --date=short --pretty=format:"%C(yellow)%h%C(white) %ad %aN%x09%d%x09%s" | awk -F"\t" "{gsub(/[, ]/,\"\",\2ドル);gsub(/HEAD/, \"033円[1;36mH033円[00m\",\2ドル);gsub(/master/, \"033円[1;32mm033円[00m\",\2ドル);gsub(/trunk/, \"033円[1;31mt033円[00m\",\2ドル);print \1ドル \"\t\" gensub(/([\(\)])/, \"033円[0;33m\\\\1円033円[00m\",\"g\",\2ドル) \3ドル}"'
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Jan 21, 2013 at 11:40

3 Comments

My current version of this script is ~300LOC and does a lot more:¶ - option to toggle oneline/multiline commit message¶ - show line whitespace/line ends in oneline mode. e.g:¶ - specify range via param¶ - Highlight issue #'s¶ - highlight /^- (Fix|Add|Refactor)/ in commit messages¶
For automated robust alias quoting, see this answer. Care to share your ~300LOC in a gist?
Thanks Tom! if I get round to posting that script (I'd need to remove some confidential/company specific stuff) I'll ping you here.
4

Try git log --pretty=fuller. It will show you:

Author:
Author Date:
Commit:
Commit Date:
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Apr 29, 2020 at 6:25

2 Comments

The OP specified that he wanted the output on a single line.
PRECISELY what I needed! Thank you! This does not change anything about the output. It just adds the relevant date information. Exactly this is the most useful answer to the use case at hand.
4

Use:

git --no-pager log --pretty=tformat:"%C(yellow)%h %C(cyan)%ad %Cblue%an%C(auto)%d %Creset%s" --graph --date=format:"%Y-%m-%d %H:%M" -25

I use an alias:

alias gitlog='git --no-pager log --pretty=tformat:"%C(yellow)%h %C(cyan)%ad %Cblue%an%C(auto)%d %Creset%s" --graph --date=format:"%Y-%m-%d %H:%M" -25'

Differences: I use tformat and isodate without seconds and time zones. With --no-pager, you will see colors

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Dec 24, 2020 at 18:18

Comments

2

The previous answers do not factor in long commit messages that would spill the log into two (or more) lines. My version here addresses just that.

This method truncates the commit message such that each commit will be restricted (automatically adjusted) to exactly one line per commit for any given terminal width:

alias gl='git log --format="%h %ad \"%<($((COLUMNS-50)),trunc)%s\" (%an)" --date=short'

gl

Output:

52f1b730 2023年10月16日 "privsep: allow __NR_clock_gettime32 syscall (#254)" (Oleg Lyovin)
6ada94b8 2023年10月12日 "privsep: allow __NR_mmap2 syscall (#253) " (Oleg Lyovin)
b976d55e 2023年10月09日 "dhcpcd: freopen of stdin/stdout may change the fd " (Roy Marples)
617a3ae2 2023年10月09日 "privsep: Log script exit status. " (Roy Marples)
45fb8fd8 2023年10月06日 "Release dhcpcd-10.0.3 " (Roy Marples)
d2870904 2023年10月04日 "DHCP6: Set all requested addrs as not stale when.." (Roy Marples)
6b22ccb2 2023年10月04日 "doc: mention using `--with-openssl` " (Roy Marples)
3c36bfc8 2023年10月04日 "IPv6: Be explicit that lifetime zero means no lo.." (Roy Marples)
500cd813 2023年10月04日 "options: introduce the uri option as opposed to .." (Roy Marples)
0b9d8825 2023年10月02日 "options: andsf6 is DHCPv6, not DHCP " (Roy Marples)
dc96a61d 2023年10月02日 "Cast a compile warning away " (Roy Marples)
cd340358 2023年09月29日 "compat: use OpenSSL RAND_priv_bytes() for entrop.." (Tobias Heider)
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Jun 5, 2024 at 21:29

Comments

2

All aforementioned suggestions use the %s placeholder for the subject. I'll recommend to use %B, because %s formatting preserves new lines and multiple lines commit message appears squashed.

git log --pretty=format:"%h%x09%an%x09%ai%x09%B"
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Apr 27, 2017 at 10:27

Comments

0

It looks like this is what you are after:

git log --pretty=" %C(reset)%ad %C(Cyan)%an: %C(reset)%s"

(In a personal note, you should always have a commit hash...)

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Oct 13, 2021 at 7:51

Comments

0

If you want to specify a file or folder, just add the path at the end:

  • %ad = author date (format respects --date=option)
  • --date=raw shows the date as seconds since the epoch (1970年01月01日 00:00:00 UTC), followed by a space, and then the timezone as an offset from UTC (reference)
git log -1 --pretty=format:"%ad" --date=raw path/to/your/folder
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Jul 20, 2021 at 2:57

Comments

0

Run this in the project folder:

git log --pretty=format:"%C(yellow)%h %ar %C(auto)%d %Creset %s , %Cblue%cn" --graph --all

And if you like, add this line to your ~/.gitconfig file:

[alias]
 ...
 list = log --pretty=format:\"%C(yellow)%h %ar %C(auto)%d %Creset %s, %Cblue%cn\" --graph --all
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Oct 9, 2017 at 2:03

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.