Git apply 不创建新文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15283332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git apply doesn't create new files?
提问by Viacheslav Kondratiuk
I'm trying to create patch by diff
and apply
it. My patch has new file and after apply
I'm getting an error.
我试图通过创建补丁diff
和apply
它。我的补丁有新文件,然后apply
出现错误。
git diff master origin/master > patch1.diff
git apply patch1.diff -v
Checking patch test3...
error: test3: No such file or directory
Patch:
修补:
diff --git a/test3 b/test3
deleted file mode 100644
index df6b0d2..0000000
--- a/test3
+++ /dev/null
@@ -1 +0,0 @@
-test3
What I'm doing wrong or git apply
doesn't create new files?
我做错了什么或git apply
没有创建新文件?
回答by Carl Norum
You're creating your patch backwards - that patch is trying to deletethat file. I think you wanted:
您正在向后创建补丁 - 该补丁正试图删除该文件。我想你想要:
git diff origin/master master > patch1.diff
You might find git format-patch
to be helpful. If you currently have master
checked out, you can just do:
你可能会发现git format-patch
它很有帮助。如果您目前已master
签出,则可以执行以下操作:
git format-patch origin/master
That command will yield a bunch of patch files, one for each commit different between your branch and origin/master
. You can then apply those using git am
and retain all of the extra data like commit message and author information.
该命令将生成一堆补丁文件,每个提交的一个补丁文件在您的分支和origin/master
. 然后,您可以使用git am
并保留所有额外数据(如提交消息和作者信息)来应用这些数据。