Here is a solution that defines a git alias, so you will be able use it like that :
git rblame -M -n -L '/REGEX/,+1' FILE
Output example :
00000000 18 (Not Committed Yet 2013-08-19 13:04:52 +0000 728) fooREGEXbar
15227b97 18 (User1 2013-07-11 18:51:26 +0000 728) fooREGEX
1748695d 23 (User2 2013-03-19 21:09:09 +0000 741) REGEXbar
You can define the alias in your .gitconfig or simply run the following command
git config alias.rblame !sh -c 'while line=$(git blame "$@" $commit 2>/dev/null); do commit=${line:0:8}^; [ 00000000^ == $commit ] && commit=$(git rev-parse HEAD); echo $line; done' dumb_param
This is an ugly one-liner, so here is a de-obfuscated equivalent bash function :
git-rblame () {
local commit line
while line=$(git blame "$@" $commit 2>/dev/null); do
commit="${line:0:8}^"
if [ "00000000^" == "$commit" ]; then
commit=$(git rev-parse HEAD)
fi
echo $line
done
}
The pickaxe solution ( git log --pickaxe-regex -S'REGEX' ) will only give you line additions/deletions, not the other alterations of the line containing the regular expression.
A limitation of this solution is that git blame only returns the 1st REGEX match, so if multiple matches exist the recursion may "jump" to follow another line. Be sure to check the full history output to spot those "jumps" and then fix your REGEX to ignore the parasite lines.
Finally, here is an alternate version that run git show on each commit to get the full diff :
git config alias.rblameshow !sh -c 'while line=$(git blame "$@" $commit 2>/dev/null); do commit=${line:0:8}^; [ 00000000^ == $commit ] && commit=$(git rev-parse HEAD); git show $commit; done' dumb_param