Partial git apply

前端 未结 3 2098
暗喜
暗喜 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: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.

提交回复
热议问题