如何应用使用 git format-patch 生成的补丁?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2249852/
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
How to apply a patch generated with git format-patch?
提问by silverburgh
I have 2 git local repositories both pointing to the same remote repository.
我有 2 个 git 本地存储库,它们都指向同一个远程存储库。
In one git repository, if I do git format-patch 1
, how can I apply that patch to the other repository?
在一个 git 存储库中,如果我这样做了git format-patch 1
,我如何将该补丁应用到另一个存储库?
回答by VonC
Note: You can first preview what your patch will do:
注意:你可以先预览一下你的补丁会做什么:
First the stats:
先上数据:
git apply --stat a_file.patch
Then a dry run to detect errors:
然后进行试运行以检测错误:
git apply --check a_file.patch
Finally, you can use git am
to apply your patch as a commit: it allows you to sign off an applied patch.
This can be useful for later reference.
最后,您可以git am
将补丁应用为提交:它允许您签署应用的补丁。
这对以后的参考很有用。
git am --signoff < a_file.patch
See an example in this article:
In your git log, you'll find that the commit messages contain a “Signed-off-by” tag. This tag will be read by Github and others to provide useful info about how the commit ended up in the code.
在您的 git 日志中,您会发现提交消息包含一个“Signed-off-by”标签。这个标签将由 Github 和其他人读取,以提供有关提交如何在代码中结束的有用信息。
回答by Jeff Dallien
git apply name-of-file.patch
回答by Dominic Cooney
Or, if you're kicking it old school:
或者,如果你把它踢成老派:
cd /path/to/other/repository
patch -p1 < 0001-whatever.patch
回答by Eugen Konkov
First you should take a note about differencebetween git am
and git apply
首先,您应该注意和之间的区别git am
git apply
When you are using git am
you usually wanna to apply many patches. Thus should use:
当您使用时,git am
您通常想要应用许多补丁。因此应该使用:
git am *.patch
or just:
要不就:
git am
Git will find patches automatically and apply them in order ;-)
Git 会自动查找补丁并按顺序应用它们 ;-)
UPD
Hereyou can find how to generate such patches
UPD
在这里你可以找到如何生成这样的补丁
回答by ice1000
If you're using a JetBrains IDE (like IntelliJ IDEA, Android Studio, PyCharm), you can drag the patch file and drop it inside the IDE, and a dialog will appear, showing the patch's content. All you have to do now is to click "Apply patch", and a commit will be created.
如果您使用的是 JetBrains IDE(如 IntelliJ IDEA、Android Studio、PyCharm),您可以将补丁文件拖放到 IDE 中,然后会出现一个对话框,显示补丁的内容。您现在要做的就是单击“应用补丁”,然后将创建一个提交。
回答by Amit Sharma
You can use below mentioned cmd
您可以使用下面提到的cmd
git apply fileName.patch