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.)
-
5Maybe you like my colored version: stackoverflow.com/a/49534733/2292766Hannes Schneidermayer– Hannes Schneidermayer2018年09月27日 12:37:14 +00:00Commented Sep 27, 2018 at 12:37
-
Colored git history using git alias: stackoverflow.com/a/63145145/7881859.Wenfang Du– Wenfang Du2023年07月13日 12:50:22 +00:00Commented Jul 13, 2023 at 12:50
17 Answers 17
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.
24 Comments
date=short like cdunn2001 suggests in another answergit log --pretty=format:"%h %ad%x09%an%x09%s" --date=shortgit log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=shortgit 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:%Salias glop="git log --pretty=format:'%C(yellow)%h|%Cred%ad|%Cblue%an|%Cgreen%d %Creset%s' --date=short | column -ts'|' | less -r"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
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 -gnow 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
9 Comments
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.> < 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?--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.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:
6 Comments
--date=short can be added to make it shorter.git log always shows the history of the currently checked out branch.%d to restore "ref names" like (HEAD -> master).reset instead of auto?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:
9 Comments
git log --pretty='%C(cyan)%ad %C(yellow)%h %C(cyan)%d %Creset%s' --date-order --graph --date=isogit 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.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:%SUse:
git log --pretty=format:"%H %an %ad"
Use --date= to set a date format:
git log --pretty=format:"%H %an %ad" --date=short
4 Comments
%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.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
4 Comments
tigin my console simply gives me an error -bash: tig: command not foundpact install tigUse
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
Comments
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'
1 Comment
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.
Comments
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ドル}"'
3 Comments
Try git log --pretty=fuller. It will show you:
Author:
Author Date:
Commit:
Commit Date:
2 Comments
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
Comments
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)
Comments
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"
Comments
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...)
Comments
If you want to specify a file or folder, just add the path at the end:
%ad= author date (format respects --date=option)--date=rawshows 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
Comments
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