部分git适用 [英] Partial git apply
问题描述
我如何让 git apply --index
不能仅仅因为单个块失败而就完全中止?我有一个100K +的补丁程序,其中删除和添加了数十个文件,执行 patch -p1
, git add
, git rm
手动跳舞.
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 pain to do the patch -p1
, git add
, git rm
dance manually.
git apply --reject --index
似乎完成了三分之二的工作:已应用补丁程序,并且已删除文件已准备好删除,但未添加新文件.
git apply --reject --index
seems to do two thirds of the work: the patch is applied and removed files are staged for deletion but new files are not added.
推荐答案
从git版本1.7.12开始, gitapply
具有-3way
(或 -3
)选项,该选项将:
Since git version 1.7.12, git apply
has a --3way
(or -3
) option which will:
- 应用它可以找出的所有更改并将其暂存(即:将它们添加到工作树和索引中),
- 添加任何新文件并将其暂存(即:将它们添加到工作树和索引中),然后
-
遇到合并冲突时,它将针对每个冲突的块:
- Apply any changes it can figure out and stage them (i.e.: add them to the working tree and index),
- Add any new files and stage them (i.e.: add them to the working tree and index), and,
When it encounters a merge conflict, it will, for each conflicting hunk:
- 从您要在
<<<<<<我们的
和=======
标记,以及 - 将补丁文件中的代码放在
=======
和>>>>>他们的
标记.
- Put the code from the branch you are patching between
<<<<<<< ours
and=======
markers, and, - Put the code from the patch file between
=======
and>>>>>>> theirs
markers.
...有冲突的文件将不会上演:您必须手动修复它们,然后 git add
之后.
... files with conflicts will not be staged: you'll have to manually fix them and git add
them afterwards.
这篇关于部分git适用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!