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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:17:06  来源:igfitidea点击:

Git apply doesn't create new files?

gitdiff

提问by Viacheslav Kondratiuk

I'm trying to create patch by diffand applyit. My patch has new file and after applyI'm getting an error.

我试图通过创建补丁diffapply它。我的补丁有新文件,然后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 applydoesn'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-patchto be helpful. If you currently have masterchecked 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 amand retain all of the extra data like commit message and author information.

该命令将生成一堆补丁文件,每个提交的一个补丁文件在您的分支和origin/master. 然后,您可以使用git am并保留所有额外数据(如提交消息和作者信息)来应用这些数据。