git log is an extremely powerful command with plenty of options that are helpful for figuring out what work has been done on your repositories and just who’s done it. This post enumerates a few of the more useful options. Most of these tips were farmed from Scott Chacon’s gitcast on git log and R. Tyler Ballance’s git protip series.
git log -<n>
Show the log for n number of commits. For example, git log -2 for the last two commits.
git log --stat
Show the log with output for files changed and insertions/deletions. Basically the normal output of git commit appended to each message.
git log --name-status
Attaches SVN-like add/modified/deleted for each commit. Very basic but still gives a decent idea about what’s changed.
git log --pretty=oneline
Compresses each commit to its SHA1 and message on one line. Pipe to wc -l if you want to count commits!
git log origin..HEAD
See if there’s any commits that have not been pushed to your origin remote. (Thanks for the tip, Ryan Bates!)
git log <file>
See all commits that affected only the file given.
git log --no-merges --author=dave
See all commits that dave has worked on, and ignore any merge commits to reduce noise.
git log --since="1 week ago"
View commits that have happened since last week. Could easily be replaced with yesterday, 1 year ago, 3 months ago, 1/20/09 and so on. There’s also other time based options: --after, --until, and --before if you want to get creative.
git log --grep='^Bump'
Search through commit messages to find ones that start with the string “Bump”. This will take in any regular expression, so if you’re looking for that one commit you did and all you can remember is a part of the message, --grep will find it.
git --no-pager log
Don’t want to use less to view your commits? This option will just give you the straight output if you need it.
Of course, check out the manpage to see all of the options available to you. If you have a nice tip that was missed and you’d like to share, let us know in the comments and I’ll update the post.