patchutils icon indicating copy to clipboard operation
patchutils copied to clipboard

grepdiff: invert match

Open camsteffen opened this issue 5 years ago • 3 comments

There should be a flag like -v, --invert-match in grep.

See https://stackoverflow.com/questions/57628550/grepdiff-find-hunks-that-dont-match-a-given-regexp (someone else's question).

My use case is to "unstage hunks that do not match" in git:

git diff --staged -U1 | grepdiff foo --invert-match --output-matching=hunk | git apply --cached -R

camsteffen avatar Dec 05 '19 20:12 camsteffen

--invert-match sounds like the right parameter name for this. Probably needs an invert_regexecs() similar to match regexecs(), and a way of switching between them appropriately (maybe a function pointer).

I don't have time to code this myself right now. Want to have a go at it?

twaugh avatar Dec 06 '19 10:12 twaugh

Thanks for your response. I'm also a little too busy to claim this right now.

camsteffen avatar Dec 07 '19 17:12 camsteffen

Would be useful indeed.

jansmets avatar Apr 11 '21 14:04 jansmets