Friday, June 22, 2018

Finding changes between branches with git.

I'm often looking for a way to find the particular changes between two branches in git. I know I can use
git log --pickaxe.
But it can be tricky to get concise output from this.

I've added an alias to my
.gitconfig
file to get me the info I want at a glance.

[alias]
    findchanges = "!f() { revision=$1; shift ;                           ⏎
… for x in $(git diff $revision --name-status | cut -f 2) ; do           ⏎ 
…    git diff $revision -U0 -- $x | grep '^[+-] ' | sed 's#^#'$x': #' ;  ⏎
… done | grep \"$@\" ;                                                   ⏎
… } ; f"

(Note: This should all be one line - I've had to break it for readability)

This lets me do the following

> git findchanges my_branch -i todo
fileA.c: +    // TODO: We really should fix this
fileB.c: -    // TODO: Make sure we tweak the frobnitz later

No comments:

Post a Comment