Partial git apply

前端 未结 3 2099
暗喜
暗喜 2021-02-12 15:40

How can I get git apply --index to not abort completely just because a single hunk fails? I have a 100K+ patch with dozens of files deleted and added, it\'d be a pa

相关标签:
3条回答
  • 2021-02-12 16:10

    Try git apply --reject <patchfile>

    0 讨论(0)
  • 2021-02-12 16:16

    Since git version 1.7.12, git apply has a --3way (or -3) option which will:

    1. Apply any changes it can figure out and stage them (i.e.: add them to the working tree and index),
    2. Add any new files and stage them (i.e.: add them to the working tree and index), and,
    3. When it encounters a merge conflict, it will, for each conflicting hunk:

      1. Put the code from the branch you are patching between <<<<<<< ours and ======= markers, and,
      2. Put the code from the patch file between ======= and >>>>>>> theirs markers.

      ... files with conflicts will not be staged: you'll have to manually fix them and git add them afterwards.

    0 讨论(0)
  • 2021-02-12 16:29

    This is what I do,

    First, perform git apply --reject. Then run git add -p and select hunks interactively. Instead of add -p you can also use other git GUIs. For adding new files add them manually if not added.

    0 讨论(0)
提交回复
热议问题