---
layout: post
title: "Git Protip: Learning from your history (git log)"
tags:
- Slide
- Software Development
- Git
created: 1228255420
---
I've been sending weekly "Protip" emails about Git to the rest of engineering here at Slide for a while now, using the "Protips" as a means of introducing more interesting and complex features Git offers. Below is the second Protip written to date.
One of the major benefits to using Git is the entirety of the repository being entirely local and easily searched/queried. For this, Git has a very useful command called git log
which allows you to inspect revision histories in numerous different ways between file paths, branches, etc. There are a couple basic scenarios where git log
has become invaluable, for me at least, in order to properly review code but also to track changes effectively from point A to point B.
git log -p --no-merges --author=dave
The --no-merges option will prevent git log from displaying merge commits which are automatically generated whenever you pull from one Git branch to another
git log --name-status master-topfriends...proj-topfriends-thing
Git supports the ability with git log and with git diff to provide unidirectional branch lookups or bidirectional branch lookups. For example, say the left branch has commits "A, B" and the right branch has commits "A, C". The ... syntax will output "C", whereas .. will output "B, C"
git log --since="2 weeks ago" --name-status -- templates
At the tail end of a git log command you can specify particular paths to look up the histories for with the -- operator, in this case, I will be looking at the changes that have occured in the templates directory over the past two weeks
git log -n 10 --no-merges -p
git log
commands automatically filter into less(1)
so you can page through the output like you would normally if you executed a svn log | less
. Because git log
is simply reading from the locally stored revision history you can quickly grep the history by any number of different search criteria to gain a better understanding of how the code base is changing and where.