jdu*_*unk 7 git patch git-apply
根据官方git 文档:
git apply
--ignore-space-change, --ignore-whitespace
When applying a patch, ignore changes in whitespace in context lines if necessary.
Context lines will preserve their whitespace, and they will not undergo whitespace fixing
regardless of the value of the --whitespace option. New lines will still be fixed, though.
Run Code Online (Sandbox Code Playgroud)
然而,基本测试表明这是一个该死的谎言。
somefile.txt使用以下内容
创建:git add somefile.txtcp somefile.txt somefile.orig.txtsomefile.txt:
git diff -w somefile.txt > somefile.gitdiffgit diff -w,生成的第 2 行(更改后的行之后的行).gitdiff将没有空格,该行显示为上下文行。diff -uw somefile.orig.txt somefile.txt > somefile.diffsomefile.txt为原始版本:git checkout somefile.txtgitdiff我们在第 5 步中创建的补丁:git apply --ignore-whitespace somefile.gitdiff再次,用文档的原话来说git apply:
应用补丁时,如有必要,请忽略上下文行中空格的更改。
这里我们得到的正是这样的:一个上下文行中的空白发生变化的补丁。因此,我们的期望是,它将按照git apply其在锡上所说的那样进行操作,并且实际上忽略此上下文行的仅空白差异,并成功而干净地应用补丁,没有任何模糊或错误。然而...
应用补丁失败:error: patch failed ... patch does not apply
应该注意的是,使用patch --ignore-whitespace -p1 < somefile.gitdiff效果很好,成功应用补丁,没有模糊或错误。
diff -w并且patch --ignore-whitespace工作完美。git等价物则不然。
注意:git v. 2.15.1我已经使用和进行了测试并遇到了相同的结果git v. 2.25.1
正如您在引用的文档中看到的,选项--ignore-whitespace和--ignore-space-change是别名。该选项的行为是忽略空白的更改,而不是忽略所有空白。
空白的更改是指添加空白字符、在空格和制表符之间更改或删除空白字符。但删除所有空白不仅仅是更改空白;还包括删除所有空白。这是一个重大变化。
在提供的示例中,从行中删除所有空格,就像删除两个单词之间的所有空格一样。这样的改变不仅仅是“空白的改变”,而是对文本的实质性改变。因此,它不会被忽视。
| 归档时间: |
|
| 查看次数: |
2055 次 |
| 最近记录: |