git-diff-grep
git-diff-grep copied to clipboard
Diffing against checkout?
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.
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.
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 ;)
I think I got it now, and I'll try to reproduce. If you find anything feel free to open a pull request.