Find where code was deleted in a Git repository

Hmph, this works for me:

$ git init
Initialized empty Git repository in /Users/pknotz/foo/.git/

$ echo "Hello" > a

$ git add a

$ git commit -am "initial commit"
[master (root-commit) 7e52a51] initial commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 a

$ echo " World" >> a

$ git commit -am "Be more specific"
[master 080e9fe] Be more specific
 1 files changed, 1 insertions(+), 0 deletions(-)

$ echo "Hello" > a

$ git commit -am "Be less specific"
[master 00f3fd0] Be less specific
 1 files changed, 0 insertions(+), 1 deletions(-)

$ cat a
Hello

$ git log -SWorld
commit 00f3fd0134d0d54aafbb9d959666efc5fd492b4f
Author: Pat Notz <[email protected]>
Date:   Tue Oct 6 17:20:48 2009 -0600

    Be less specific

commit 080e9fe84ff89aab9d9d51fb5d8d59e8f663ee7f
Author: Pat Notz <[email protected]>
Date:   Tue Oct 6 17:20:33 2009 -0600

    Be more specific

Or, is this not what you mean?


git log -S<string> does the job, but if you need to make more complex searches you can use git log -G<regex>.

From the man:

-G<regex>

Look for differences whose patch text contains added/removed lines that match <regex>.