Usecases With Git Log

Git-Logo-2Color

I did a lightning talk (< 10 min) about ‘git log’ @ Montreal.rb yesterday. My sources were Scott Chacon’s git log screencast, Nick Quaranto’s gitready post, as well as git-log manpages. Here are my notes:

Usecase: I want to be up to date with the latest activity

git log
git log -4
git log --since="1 day"
git log --since="2 hour"
git log -2 --stat
git log -2 --name-status
git log --since='2009-05-05' --until='3 days'
git log i-2 --author='Martin C'
git log 9485fdd2..7b766227 # optionally specify a file

Usecase: I want the latest changes on a specific file

git log [file] # gives you all commits for that specific file
git log -3 [file] # gives you the 3 last commits
git log -p [file] # gives you all diffs for every commit of that file
git log -2 -p db/schema.rb
git blame [file] # gives SHA1, author, line changed, app/controllers/questions_controller.rb

Usecase: I want the changes of a commit you partly remember the comment

git log --pretty=oneline | grep [comment
git log --grep='^user icon'
git log --grep='user icon' -i
git show [SHA1]
git show [SHA1]:[file

Usecase: I want stats on commits

git log --pretty=oneline | wc -l
git log --pretty=oneline --no-merges | wc -l  # no-merges: do not show commits that have more than 1 parent
 
git log --pretty=oneline --author='Martin C' | wc -l
git log --pretty=format:'%an' | sort | uniq -c | sort -n
 
git log --pretty=format:'%h by %an'
git log -4 --pretty=format:'%h (%H) by %an %ar (%ad) %s'
git log -4 --pretty=format:'%h by %an %ar (%ad) %s' db/schema.rb
Advertisements

One comment

  1. Cool, thanks.

Got a comment?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: