726

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)

James Raitsev
  • 92,517
  • 154
  • 335
  • 470
Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155

16 Answers16

1069
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
                                                                              

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.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155
  • 13
    ... and it is also useful to add `date=short` like cdunn2001 suggests in another answer – Jesper Rønn-Jensen Jan 10 '12 at 21:41
  • 17
    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` – Jesper Rønn-Jensen Jan 10 '12 at 21:41
  • 202
    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` – kynan Feb 05 '12 at 00:24
  • @kynan nice touch with the colors:) Although i find them a little too bright for the purpose – Jesper Rønn-Jensen Feb 06 '12 at 14:44
  • 25
    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"` – Ciro Santilli OurBigBook.com Mar 27 '14 at 23:33
  • 1
    both Jesper and Ciro's solution, cannot align different length of author name, same result. use Jesper's as it's simpler. – liuyang1 Feb 12 '15 at 03:06
  • @liuyang1 Here's a way of formatting the name to some reasonable fixed number of characters, say 30, using 'awk' instead of 'columns': alias glop="git log --pretty=format:'%C(yellow)%h|%Cred%ad|%Cblue%an|%Cgreen%d %Creset%s' --date=short|awk -F'|' '{printf \"%s %s %-30s %s\n\", \$1,\$2,\$3,\$4}'" – amdn Oct 22 '15 at 18:53
  • 1
    @liuyang1You dont need to cal `awk`, since git log formatter has `trunc` for truncation. Ask a new question not to sidetrack this question further – Jesper Rønn-Jensen Oct 23 '15 at 10:11
  • 19
    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 https://www.kernel.org/pub/software/scm/git/docs/git-log.html (PRETTY FORMATS section) – Vivek Oct 28 '15 at 12:18
  • 1
    this is too easy to remember make it more complex – Muhammad Umer Jun 29 '16 at 17:00
  • 2
    use an alias @MuhammadUmer – pcarvalho Aug 28 '16 at 14:07
  • I'm basically doing what is done here, but outputting to a file (without colours). How would I get each commit to show on its own line? `git log --pretty=format:'%h %ad %an%d %s' --date=short > file.txt` – Bird87 ZA Oct 18 '17 at 09:56
  • 1
    Thanks. I find it pleasing to have the date column first before username for better alignment – daparic Sep 01 '18 at 11:45
  • 1
    You may want to try `%C(auto)` in the format string. I would also suggest using `tformat` instead of `format` or the end of the last line is probably incorrect (= missing linefeed). Note that if you skip the `format:` prefix, `tformat:` is assumed. – Mikko Rantalainen Nov 06 '18 at 13:03
  • 2
    Use `--date=iso` for YYYY-MM-DD dates; and `--date=relative` for `5 days ago` dates. – Lassi Jul 19 '20 at 07:42
  • git log --pretty=format:"%h %an %x09 %ad %x09 %s" --date=short – rjha94 Nov 22 '20 at 03:16
  • 1
    Note that the official documentation for this answer can be found in `man git log`, then search for `%h` by typing `/%h` and pressing Enter. This will quickly jump you down to the `format:` section of the man pages, which lists out all of these `%` options for the format string. – Gabriel Staples Feb 21 '21 at 05:16
  • If you like @kynan's colors and @Ciro's columns, but found that `columns` is removing the colours, then you can use the pretty-format `%<(N)` [column formatting](https://git-scm.com/docs/pretty-formats#Documentation/pretty-formats.txt-emltltNgttruncltruncmtruncem) (in 1.8.3 or newer) instead of `columns`. E.g. `git log -S analytics --abbrev-commit --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%<(20)%an %Cgreen%d %Creset%s' --date=short`. _(Note: this causes characters with accents, like Š, to take up an extra space, at least in my terminal, but the output still looks great for me)_ – Daryn Jun 03 '21 at 09:37
  • Why is the SHA so short? – Sam Sep 09 '21 at 18:47
  • `alias gl="git log --pretty=format:'%h%x09%an%x09%ad%x09%s'"` – SIMMORSAL Aug 03 '22 at 05:22
  • 2
    if you want comparable dates then add `--date=format-local:%Y.%m.%d-%H:%M:%S`. And since commiter names may contain spaces, it's more convenient to put the date first: `--pretty=format:"%h%x09%ad%x09%an%x09%s"` – bebbo Mar 26 '23 at 20:11
266

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 you@me.com lsof is a dependency now.
0754f18 11 hours ago you@me.com Properly unmount, so detaching works.
336a3ac 13 hours ago you@me.com Show ami registration command if auto register fails
be2ad45 17 hours ago you@me.com Fixes #6. Sao Paolo region is included as well.
5aed68e 17 hours ago you@me.com 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

andsens
  • 6,716
  • 4
  • 30
  • 26
  • 4
    You can shorten the lines even more by using a [mailmap](https://www.kernel.org/pub/software/scm/git/docs/git-shortlog.html#_mapping_authors). I have abbreviated the names of colleagues at my workplace down to only their first name :-) – andsens Oct 18 '13 at 05:04
  • 2
    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. – Brent Faust Dec 06 '13 at 19:56
  • 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? – Victor Basso Mar 18 '16 at 10:36
  • +1 for stating that `ad` respects the `--date` option and permanently storing a default in gitconfig. I used `ar` before and had no easy way for switching between formats, when I needed an exact timestamp – dfherr Jan 16 '17 at 12:03
  • I'm having a hard time configuring my `.gitconfig`, even with your snippets I'm not sure in what sections to put them and how to use them. I've tried a few times to no result. can you post your `.gitconfig` file? – Alvaro Cavalcanti Jun 07 '17 at 14:42
  • 1
    @AlvaroCavalcanti sure no problem! https://gist.github.com/andsens/3ba598d829e948e1bf816e2c4cd5f282 – andsens Jun 08 '17 at 08:22
  • @andsens Perfect! Thanks! – Alvaro Cavalcanti Jun 08 '17 at 11:56
  • @andsens Do you know how to only apply the gitconfig's pretty format to command with --oneline, but leave "git log" alone? – Trần Việt Hoàng Oct 16 '17 at 15:07
  • 2
    @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`. – andsens Oct 16 '17 at 17:01
140

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

Hannes Schneidermayer
  • 4,729
  • 2
  • 28
  • 32
127
git log --pretty=format:"%H %an %ad"

use --date= to set a date format

git log --pretty=format:"%H %an %ad" --date=short
knittl
  • 246,190
  • 53
  • 318
  • 364
  • 1
    Great! Next time I'll probably only use %h over %H as the hash is just nonsense for my human eyes:) – Jesper Rønn-Jensen Sep 17 '09 at 20:08
  • 3
    Cool! I was not aware of --date=short – Jesper Rønn-Jensen Sep 20 '09 at 20:26
  • 4
    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 Jan 03 '17 at 16:30
  • 1
    @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. – M. Justin Oct 22 '20 at 04:55
98

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

Use predefined git alias (hs - short for history):

git hs

Created once by 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:

Wenfang Du
  • 8,804
  • 9
  • 59
  • 90
  • 4
    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` – Ryan Aug 25 '20 at 21:07
  • 2
    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 Jan 27 '21 at 18:23
  • 1
    @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 Aug 26 '21 at 12:50
  • 1
    @elady See [here](https://stackoverflow.com/q/7651644/7881859). – Wenfang Du Aug 26 '21 at 22:32
  • 1
    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` – elady Aug 29 '21 at 05:05
  • How did you create the wonderful (transparent, rounded) console screenshot ? – hc_dev Jul 04 '23 at 06:24
  • @hc_dev iShot Pro – Wenfang Du Jul 04 '23 at 06:35
59

tig is a possible alternative to using the git log command, available on the major open source *nix distributions.

On debian or ubuntu try installing and running as follows:

$ sudo apt-get install tig

For mac users, brew to the rescue :

$ brew install tig

(tig gets installed)

$ tig

(log is displayed in pager as follows, with current commit's hash 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 capital D (note: lowercase d opens a diff view.) Configure it permanently by adding show-date = short to ~/.tigrc; or in a [tig] section in .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 *nix 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

computingfreak
  • 4,939
  • 1
  • 34
  • 51
Joe Generic
  • 699
  • 5
  • 3
38
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. (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
bishop
  • 37,830
  • 11
  • 104
  • 139
Sean
  • 1,149
  • 18
  • 28
33

Use predefined git alias, i.e.:

$ git work

Created once by command:

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

https://git-scm.com/book/tr/v2/Git-Basics-Git-Aliases

Or more colored with 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

Míra
  • 1,465
  • 16
  • 13
  • one can have columns that line up and a graph https://stackoverflow.com/questions/46229359/how-to-do-alignment-in-git-logs-with-graph – user1133275 Nov 08 '20 at 10:54
8
git log --pretty=format:'%h %ad  %s%x09%ae' --date=short

Result:

e17bae5 2011-09-30  Integrate from development -> main      nixon@whitehouse.gov
eaead2c 2011-09-30  More stuff that is not worth mentioning bgates@apple.com
eb6a336 2011-09-22  Merge branch 'freebase' into development        jobs@nirvana.org

Constant-width stuff is first. The least important part -- the email domain -- is last and easy to filter.

neu242
  • 15,796
  • 20
  • 79
  • 114
cdunn2001
  • 17,657
  • 8
  • 55
  • 45
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;36mH\033[00m",$2);gsub(/master/, "\033[1;32mm\033[00m",$2);gsub(/trunk/, "\033[1;31mt\033[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;36mH\033[00m",$2);
         gsub(/master/, "\033[1;32mm\033[00m",$2);
         gsub(/trunk/, "\033[1;31mt\033[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;36mH\033[00m\",\$2);gsub(/master/, \"\033[1;32mm\033[00m\",\$2);gsub(/trunk/, \"\033[1;31mt\033[00m\",\$2);print \$1 \"\t\" gensub(/([\(\)])/, \"\033[0;33m\\\\\1\033[00m\",\"g\",\$2) \$3}"'

(Is there an easier way to escape that? it was a bit tricky to work out what needed escaping)

Sam Hasler
  • 12,344
  • 10
  • 72
  • 106
  • 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¶ – Sam Hasler Aug 04 '14 at 13:51
  • For automated robust alias quoting, see [this answer](http://stackoverflow.com/a/39616600/5353461). Care to share your ~300LOC in a gist? – Tom Hale Oct 05 '16 at 04:25
  • 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. – Sam Hasler Oct 05 '16 at 13:37
4
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 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

Sérgio
  • 6,966
  • 1
  • 48
  • 53
2

All aforementioned suggestions use %s placeholder for 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"
Community
  • 1
  • 1
palik
  • 2,425
  • 23
  • 31
2

Try git log --pretty=fuller, it will show you:- Author: Author Date: Commit: Commit Date:

Hope this helps.

Varun Sharma
  • 530
  • 5
  • 10
0

Run this in 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:

[alias]
    ...
    list = log --pretty=format:\"%C(yellow)%h %ar %C(auto)%d %Creset %s, %Cblue%cn\" --graph --all
MUH Mobile Inc.
  • 1,462
  • 1
  • 16
  • 25
0

If you wanna 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
Alessia
  • 899
  • 10
  • 16
0

looks like this is what you are after:

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

(in personal note you should always has commit hash..)

Amazia Gur
  • 1,692
  • 17
  • 16