Viewing Commit History with Git Log

Last modified: 
Friday, August 28th, 2015
Topics: 
Git

Default output

git log

Default output plus diff info (-p flag)

git log -p

Default output limited to last n entries

git log -3 outputs last 3 entries.
git log -6 outputs last 6 entries.

Show stat information

git log --stat

commit 67aba32eca6794dc89f34bde1680b5d52fcb9998
Author: Erik Smith 
Date:   Fri Aug 28 11:03:19 2015 -0400

    Adds error handling for Eventbrite.com API error responses.

 sites/default/modules/ebv3/includes/Ebv3Api.inc    | 31 +++++++++++++++++++++++--------
 sites/default/modules/ebv3/includes/Ebv3Logo.inc   |  1 +
 sites/default/modules/ebv3/includes/ebv3.admin.inc |  2 +-
 3 files changed, 25 insertions(+), 9 deletions(-)

Show only commit numbers and log messages

git log --pretty=online

17131853d65915d788483679616a8e5bfa401390 Live debugging on Dev.
1eb51c73ba7567d58036a466bd4958baac63244a Creates destination directory.
21c069a4080bac1b1932fe9f6767b6d235536816 slick adjustment
edcdc010bdda2dc9cb56f03fe08af72b6e2d294a Fixes hook_update_n() number.
a92f46584edfbae0d5d36f86a853cb6fc36c5934 Logic for retrieving logo file object data.

Define your own format

git log --pretty=format:'%h - %an, %ar : %s'

062947c - Erik Smith, 23 hours ago : Adds a new column to track logo ids.
d0d0bf3 - Erik Smith, 24 hours ago : Removes short-circuit used for debugging.
3edf922 - Erik Smith, 25 hours ago : Merge branch 'feature/features-updates'
7f39ff1 - Erik Smith, 25 hours ago : Updates support feature.

Find all commits by author

git log --pretty='%h %an %ar %s' --author='Erik Smith'

1eb51c7 Erik Smith 20 hours ago Creates destination directory before allowing event import to proceed.
edcdc01 Erik Smith 21 hours ago Fixes hook_update_n() number.
00d9b2e Erik Smith 23 hours ago Adds tracking of logo id on Event creation.
062947c Erik Smith 23 hours ago Adds a new column to track logo ids.
d0d0bf3 Erik Smith 25 hours ago Removes short-circuit used for debugging.
3edf922 Erik Smith 25 hours ago Merge branch 'feature/features-updates'
7f39ff1 Erik Smith 25 hours ago Updates Eventbrite support feature.

Only show commits with a commit message containing the string

git log --pretty='%h %an %s' --author='Dries Buytaert' --grep='logo' -5

Here I have requested the last 5 commits authored by Dries Buytaert with log messages containing the string 'logo'.

a0b2c8e Dries Buytaert - Patch #972136 by tim.plunkett, starnox: site name alignment wrong with no logo.
ec97ffd Dries Buytaert - Patch #848312 by Jeff Burnz, tsi, jensimmons, tim.plunkett, aspilicious, bleen18: better Druplicon logo for Bartik.
86e806f Dries Buytaert - Patch #653234 by timmillwood: make Druplicon look inward until we figure out what to do with the logomark.
9381abb Dries Buytaert - Patch #470998 by bleen18: properly align the Druplicon logo in Garland.
4718f59 Dries Buytaert - Patch #316515 by jmburnz, momendo: fixed position of OpenID logo.

Show commits adding or removing code matching the string -S

git log -p --author='Erik Smith' -SHandleCommonErrors -1

Here I am querying for my last commit with a code change containing the string 'HandleCommonErrors'.

commit 67aba32eca6794dc89f34bde1680b5d52fcb9d6b
Author: Erik Smith 
Date:   Fri Aug 28 11:03:19 2015 -0400

    Adds error handling for Eventbrite.com API error responses.

diff --git a/sites/default/modules/ebv3/includes/Ebv3Api.inc b/sites/default/modules/ebv3/includes/Ebv3Api.inc
index 2925949..6aa702b 100644
--- a/sites/default/modules/ebv3/includes/Ebv3Api.inc
+++ b/sites/default/modules/ebv3/includes/Ebv3Api.inc
@@ -38,17 +38,27 @@ class Ebv3Api {
   public function request($request, $options = array()) {
     $result = drupal_http_request($request, $options);
-    if ($result && (int) $result->code === 200) {
+    if ($result) {
       $data = json_decode($result->data);
-      return $data;
+      if ($result->code == 200) {
+        return $data;
+      }
+      else {
+        $this->HandleCommonErrors($data);
+        return FALSE;
+      }
     }

Show branching graph

git log --pretty=format:'%h - %an %s' --graph


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.