git-diff-grep icon indicating copy to clipboard operation
git-diff-grep copied to clipboard

Diffing against checkout?

Open tdavis opened this issue 13 years ago • 3 comments

The script seems to always be diffing against my checkout which means that if I do a grep against the past 100 commits and 50 commits into the history it finds one with a match, it will continue finding that same match and diff for the next 49 commits. I changed instances of git diff to git diff-tree -p to remedy this. I also changed the initial search to grep -q "^[+-].*$query.*" which ensures that source context doesn't cause a commit to match.

I feel like I may be missing something obvious or this is a platform-specific issue because the script flat doesn't do what it claims on my system. If these are actual bugs and not platform quirks I will be happy to create a pull request for the changes.

tdavis avatar Dec 30 '11 21:12 tdavis

Hi, so what you want to do is stop at the first match? If that's correct there may be a simpler way which I can try.

oscardelben avatar Jan 03 '12 08:01 oscardelben

No, that's not what I mean. The problem is that git diff <commit> compares <commit> with the working tree; it doesn't spit out the commit's absolute changes (e.g. the diff between <commit> and its sibling). Perhaps this is what you intended--to diff every previous commit with the working tree and find the requested query. However, I found this less than helpful because if I'm at "revision 50" and "revision 25" has the query I'm looking for, every subsequent commit through "revision 0" will also match for that query, since technically speaking the diff of that commit against my working tree includes it--but it's misleading because the change wasn't actually made in any of the subsequent commits! This was further compounded by the fact that context-only lines were being matched as well.

I hope I've explained it more clearly this time; this is really tough without a sample repository ;)

tdavis avatar Jan 03 '12 14:01 tdavis

I think I got it now, and I'll try to reproduce. If you find anything feel free to open a pull request.

oscardelben avatar Jan 03 '12 15:01 oscardelben