简体   繁体   English

修补程序与系统的修补程序一起应用,但被git-apply拒绝

[英]Patch applied with system's patch but rejected by git-apply

I'm trying to understand how does git apply unified diffs. 我试图了解git如何应用统一差异。

I wrote the following "identity" patch: 我写了以下“身份”补丁:

--- a/js/controllers.js
+++ b/js/controllers.js
@@ -15,3 +15,3 @@
-  '$location',
-  function ($scope, $routeParams, $location) {
-    doSomething();
+  '$location',
+  function ($scope, $routeParams, $location) {
+    doSomething();

The system's patch command applies this patch with success while git-apply gives the following output: 系统的patch命令成功应用此补丁,而git-apply提供以下输出:

error: patch failed: [...]js/controllers.js:15
error: [...]js/controllers.js: patch does not apply

I don't understand why. 我不明白为什么。

Your patch has no context. 您的补丁程序没有上下文。 diff would have included a few unmodified lines before and after the changes as well. diff在更改前后也会包含一些未修改的行。 From the git apply documentation: git apply文档中:

--unidiff-zero

By default, git apply expects that the patch being applied is a unified diff with at least one line of context. 默认情况下,git apply期望所应用的补丁是具有至少一行上下文的统一差异。 This provides good safety measures, but breaks down when applying a diff generated with --unified=0 . 这提供了良好的安全措施,但是在应用--unified=0生成的diff时会--unified=0 To bypass these checks use --unidiff-zero . 要绕过这些检查,请使用--unidiff-zero

Note, for the reasons stated above usage of context-free patches is discouraged. 注意,由于上述原因,不建议使用无上下文修补程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM