Friday, September 21, 2012

Usecases using git log

ref:http://dev-logger.blogspot.sg/2009/05/usecases-using-git-log.html

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

No comments:

Post a Comment