Add patch in git, all hunks matching regex in file

前端 未结 3 546
花落未央
花落未央 2021-02-04 01:46

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.

3条回答
  •  执念已碎
    2021-02-04 02:16

    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"
    
    

提交回复
热议问题