Find where code was deleted in a Git repository
git
Solution
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 <patnotz@gmail.com>
Date: Tue Oct 6 17:20:48 2009 -0600
Be less specific
commit 080e9fe84ff89aab9d9d51fb5d8d59e8f663ee7f
Author: Pat Notz <patnotz@gmail.com>
Date: Tue Oct 6 17:20:33 2009 -0600
Be more specific
Or, is this not what you mean?
Problem
How do I find code that was deleted? I ended up finding where it was created with this: ``` $ git log --pretty=oneline -S'some code' ``` And that's good enough, but I was also curious to find where it got deleted, and so far, no dice. First, I tried `git diff HEAD..HEAD^ | grep 'some code'`, expanding the range each time, until I found the lines where it was removed. Nice, so suppose I found it on range `HEAD^^..HEAD^^^`, then I do `git show HEAD^^^` and `git show HEAD^^` with `grep`, but the code is nowhere to be found! Then I read up a bit on `git bisect`, and sure enough, it gives me a single revision where the culprit is supposed to be... Again, `git show rev | grep 'some code'` comes up empty... What am I doing wrong?