Add patch in git, all hunks matching regex in file

前端 未结 3 550
花落未央
花落未央 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:15

    Sadly, the patch in July 2011 went nowhere for now.
    It would have introduced a git add --hunks=magic option.

    For now, you will have to do with:

    • extracting a patch based on your regexp: see "Filtering a diff with a regular expression"
    • git stash your changes
    • apply your patch and git add
    • reset your index and apply your stash (git stash pop)

    Quite a cumbersome process.

提交回复
热议问题