Is there a way to add all hunks in a file matching a regex?
I know I can search for a given hunk with /, but that only finds the first. I want to add all matching.
Adding to the answer of @raphinesse and comments by @rubystallion, in addition to tips on how to format it from here, I made a git function to do this with the regex as the only input. Just enter this into your gitconfig (I used my global gitconfig) and use it with git regexadd
.
[alias]
regexadd = "!f() { git diff -U0 \
| grepdiff -E $1 --output-matching=hunk \
| git apply --cached --unidiff-zero; }; f"