Git Tips, Tricks and Notes
Find all commits that added/deleted the given string
$ git log -p -S 'api_key =' --source --all
Find all commits that added/deleted the given string, excluding the specified directories
$ git log -p -S some_method -- . ":(exclude)vendor/*"
Get the git blame of the previous commit for a given line
# git blame -L{LINE_NUMBER},+{CONTEXT} SHA^ -- {FILE_PATH}
$ git blame -L165,+1 5c2eb904^ -- app/models/public_body.rb
Source: http://stackoverflow.com/questions/5098256/git-blame-prior-commits
Run specs on each commit of a branch
$ git rev-list --reverse develop..feature_x | while read rev; do git co $rev && git clean -fd && bin/rspec; done; git co feature_x
Source: https://www.destroyallsoftware.com/screencasts/catalog/source-code-history-integrity
Show which files have been changed between two branches in a given directory
$ git diff --name-status master..release/0.22 app/views/
Show commits in current branch not in master
$ git log --cherry-pick --topo-order --reverse master...
Source: http://stackoverflow.com/questions/53569/how-to-get-the-changes-on-a-branch-in-git
Show commits in the current branch that modify a given file
# Assuming you're on a feature branch created from master
$ git log --follow master.. -- path/to/file
Nicer CSV diffs
$ git diff --color-words='[^,]+'