我在Windows上使用git,它的工作方式与Linux有些不同。具体来说,我发现当我运行以下命令时:
git apply -R C:\downloads\mypatch.patch
这可能是在错误的目录中运行。我不得不将它复制到我正在应用补丁的本地目录中。我还遇到了一些错误,例如:
error: product/build.gradle: No such file or directory
error: main/generator/generator.js: No such file or directory
这些文件非常奇怪,因为这些文件在我补丁中指定的目录中。我找到的唯一解决办法是手动修改补丁。我不得不在目录和文件名前添加
./
。所以我把它改成了这样:
Index: build_scripts/product/build.gradle
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- build_scripts/product/build.gradle (revision 537fbcc1ebdf65652896eaaf2a315cc44a24ba6c)
+++ build_scripts/product/build.gradle (date 1594123740523)
@@ -304,7 +304,7 @@
from("$repoRootDir/src/main/nodejs/utils/") {
include "common_*.js"
}
转换为:
Index: ./build_scripts/product/build.gradle
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- ./build_scripts/product/build.gradle (revision 537fbcc1ebdf65652896eaaf2a315cc44a24ba6c)
+++ ./build_scripts/product/build.gradle (date 1594123740523)
@@ -304,7 +304,7 @@
from("$repoRootDir/src/main/nodejs/utils/") {
include "common_*.js"
}
唯一的变化是在3个不同的"build_scripts/product/build.gradle"字符串之前添加了"./"。
另外,另一个好的提示是git apply命令可以使用"-v"参数来提供更多详细信息,这样你可以看到它首先检查补丁是否安全可应用,然后再应用补丁。
git diff --patch
命令,那么git apply -R <patch>
命令无法起作用吗? - Ash