Git log


Notes on different log outputs that Git provides

The following command is perfect for piping values to other formats:

git log --pretty=format:"Sha1: %h Date:%cd"

Formating example:

Command: git log --pretty=format:"Author:%an%nDate:%cr%nSubject:%s%nBody:%b"

formatting

  • %h hash (sha1)
  • %n newline
  • %s commit msg subject (aka title)
  • %b commit msg body (aka description)
  • %an author name
  • %cr relative date (4 hours ago)

**Output: **

Author:John
Date:24 hours ago
Subject:'Files modified: 1'
Body:'Modified 1 file:README.md'

Date formatting:

  • %cd committer date -> Thu Dec 3 16:59:09 2015 +0100
  • %cD committer date, RFC2822 style -> Thu, 3 Dec 2015 16:59:09 +0100
  • %cr committer date, relative -> 1 year ago
  • %ct committer date, UNIX timestamp -> 1449158349
  • %ci committer date, ISO 8601-like format -> 2015-12-03 16:59:09 +0100 πŸ‘ˆ
  • %cI committer date, strict ISO 8601 format -> 2015-12-03T16:59:09+01:00

Restrict amount

git log -3 Will then show details about the last 3 commits

Restrict and pretty:

git log -3 --pretty=format:"Sha1: %h" (%H for full sha1)

Sha1: ad3f020
Sha1: 4caecd0
Sha1: 6e10975

Count of Commits Between Two Commits (sha1 as identifier)

git rev-list [first] ^[second] --count (remember to remove the Square brackets)

Git log range based on date

git log --after="2015-11-12 00:00" outputs the log after a date git log --after="2016-11-12 00:00" --format=oneline | wc -l outputs :9 (the wc -l πŸ‘‰ linecount)

Fancy github graph for a repo:

git log | grep Date | awk '{print " : "$4" "$3" "$6}' | uniq -c

   3  : 10 Dec 2016
   1  : 25 Nov 2016
   2  : 2 Nov 2016
   1  : 1 Nov 2016
   1  : 18 Oct 2016
   1  : 13 Oct 2016
   2  : 4 Oct 2016
   1  : 17 Sep 2016
   1  : 5 Sep 2016
   1  : 22 Aug 2016
   1  : 21 Aug 2016
   1  : 18 Aug 2016
   7  : 17 Aug 2016
   8  : 16 Aug 2016
   1  : 15 Aug 2016

Total commit count:

git log --pretty=format:"Sha1: %h" | wc -l outputs correct count git rev-list HEAD --count <–this is faster, but gives +1 count

Git show:

git show head~9 --pretty=format:"%ci" --no-patch πŸ‘ˆ (no-patch suppresses the diff)

  • head~9 πŸ‘‰ represents commit 9 commits from the latest commit, make sure you assert there is enough commits first
  • "%ci" πŸ‘‰ represents date in this format: 2015-12-03 16:59:09 +0100 πŸ‘ˆ (this would also be the output of the command)