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" // This one is nice when creating release-notes, use a big window, copy everything

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="2023-05-05 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

Get a nice overview of last commits (color coded):

Really nice. Esp if you combine it with --after="2022-12-1 etc

alias glog="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

output:

* 98c4e544 - (HEAD -> main) Begin fixing detail alert logic (87 minutes ago) <eonist>
* 7b7321cc - (origin/main, origin/HEAD) Begin fixing detail cancel alert (17 hours ago) <eonist>
* 7375b113 - Tweak UI for NavHeader (18 hours ago) <eonist>
* 3f3f207a - Begin fixing DetailHeader for iOS (26 hours ago) <eonist>
* 3e24beb2 - Fix issues with unarchive scene and password prompt scene (2 days ago) <eonist>
* 62e5993d - Fix UITest support for persistence class (2 days ago) <eonist>
* 3508a285 - Fix deprecated calls + Fix UITest bug (3 days ago) <eonist>
* bc12332a - Remove all forced unwraps #649 (3 days ago) <eonist>

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)