18 Jan 2012

[cheetsheet] git history

Base command:

git log

Log output formatting:
# view patches
git log -p  

# view statistics
git log --stat 
 
# preset formats
git log --pretty=raw 

# custom format   
git log --pretty=format:"The author of %h was %an, %ar%nThe title was >>%s<<%n" 

# branch graph
git log --pretty=oneline --graph


Commit filtering:
# date ranges
git log --before="2 weeks ago" --after="2009-01-26" --pretty=oneline

# looking for people
git log --author=johannes.schindelin --since="14 days ago" --pretty=oneline 

OR
git log --author=Junio
git log --author=Hamano
git log --author="Junio C Hamano"
git log --author=gitster@pobox.com 

git log --author=gmail --pretty=format:"%ae" | wc -l
git log --author='\.mil' --pretty=format:"%ae" | wc -l


Search Commit Messages
git log --grep='C90' --pretty=oneline


File history
#see every commit that modified the ‘notes.c’ file 
git log --pretty=oneline -- notes.c   

#see which commits changed any of the files in the ‘t/lib-httpd’ directory 
git log --pretty=oneline --all -- t/lib-httpd/   


Other options
# exclude merge
git log --grep='C90' --pretty=oneline --no-merges

# last N commits
git log --pretty=oneline --no-merges -5 


Tip 1
# view commits between to specific commits
git log --pretty=oneline 710f0f..8a5cbc 


Tip 2
# If you are on your ‘master’ branch and wanted to see each of the commits that are on
# your  ‘experiment’ branch that are not yet merged in, you can run
git log master..experiment --pretty=oneline

# the same (but from any branch included master)
git log ..experiment --pretty=oneline 

# And also if you are on the ‘experiment’ branch and want to see the same information - everything 
# that is on your current branch that have not been merged into ‘master’ yet, you can run this: 
git log master.. --pretty=oneline 


Veru usefull commands (via http://learn.github.com/p/log.html)

1 comment: