Git: What did I last do?

Russell Bateman
23 March 2012
last update:

You wish you could remember the message you wrote for the last or recent commits.

russ ~/acme/rest-server $ git log | head
commit 24a1f77b80227912802135535a6ad1c0c0dd7382
Author: Russell Bateman 
Date:   Fri Mar 23 08:09:17 2012 -0600

    Genericized the JSON formatting for the Wicket page display. Added
    other entities to this coverage: Country, Language and AddressType.
    Reduce technical debt considerably (hehehe) by discarding much code
    and many identifiers through refactoring while readying this whole
    mechanism to support additional types of display.

Here's how to see all commit messages. Press 'q' as soon as you're tired of viewing them.

russ ~/acme/rest-server $ git log | less
commit 24a1f77b80227912802135535a6ad1c0c0dd7382
Author: Russell Bateman 
Date:   Fri Mar 23 08:09:17 2012 -0600

    Genericized the JSON formatting for the Wicket page display. Added
    other entities to this coverage: Country, Language and AddressType.
    Reduce technical debt considerably (hehehe) by discarding much code
    and many identifiers through refactoring while readying this whole
    mechanism to support additional types of display.

commit a6c63d03a2205c5d0ec52ddfa8a4a632ff98547e
Author: Russell Bateman 
Date:   Thu Mar 22 18:50:30 2012 -0600

    Yeah, baby! C function pointers in Java. You saw it here first.
    This fixes up the "Supported States" display on the Application
    Examples page and stirs the pot for more stuff like it.

commit efc22ef565846e3d8fbed52e4cafb4c4ca6bd56a
Author: Russell Bateman 
Date:   Thu Mar 22 17:29:43 2012 -0600

    Enhanced what's on the home page plus fixed the styles especially
    so that headings show up better against the added text blurbs.
: q

Search for something

Or, you want to find out if there's a record containing a specific keyword. Just pipe the output of git log to less, press '/' and type in your search string. less has some vi capabilities and will search for and reposition itself at occurrences of your search string. You can use your arrow keys to move back up or down in context.

Seeing filenames as well as commit messages

There are three levels of this and these are very cool and useful:

  1. git log --name-only —show only filepaths
  2. git log --name-status —show status (a letter) and filepaths
  3. git log --stat —show filepaths with commit information

Per-file history

  1. git log -p <filename>