从 git 存储库创建补丁或差异文件并将其应用到另一个不同的 git 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28192623/
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
Create patch or diff file from git repository and apply it to another different git repository
提问by zatamine
I work on WordPress based project and I want to patch my project at each new release version of WP. For this, I want generate a patch between two commits or tags.
我从事基于 WordPress 的项目,我想在 WP 的每个新发布版本上修补我的项目。为此,我想在两个提交或标签之间生成一个补丁。
For example, in my repo /www/WP
I do this :
例如,在我的回购中,/www/WP
我这样做:
$git patch-format com1..com2 --stdout > ~/patchs/mypatch.patch
$git patch-format com1..com2 --stdout > ~/patchs/mypatch.patch
Or
或者
$git patch-format tag1..tag2 --stdout > ~/patchs/mypatch.patch
$git patch-format tag1..tag2 --stdout > ~/patchs/mypatch.patch
/www/WP
git natif WordPress
/www/WP
git natif WordPress
/www/myproject
My git project WordPress based
/www/myproject
我的 git 项目基于 WordPress
The git apply
command line doesn't work, I think because we are in different repositories.
该git apply
命令行是不行的,我想是因为我们是在不同的存储库。
Can I generate a patch file without a commit, just a differential and apply it to another git repository ?
我可以生成一个没有提交的补丁文件,只是一个差异并将其应用到另一个 git 存储库吗?
Thanks advance.
先谢谢了。
回答by Enrico Campidoglio
You can just use git diff
to produce a unified diffsuitable for git apply
:
您可以使用git diff
来生成适合于的统一差异git apply
:
git diff tag1..tag2 > mypatch.patch
You can then apply the resulting patch with:
然后,您可以应用生成的补丁:
git apply mypatch.patch
回答by kenorb
To produce patch for several commits, you should use format-patch
git command, e.g.
要为多个提交生成补丁,您应该使用format-patch
git 命令,例如
git format-patch -k --stdout R1..R2
This will export your commits into patch file in mailbox format.
这会将您的提交以邮箱格式导出到补丁文件中。
To generate patch for the last commit, run:
要为最后一次提交生成补丁,请运行:
git format-patch -k --stdout HEAD^
Then in another repository apply the patch by am
git command, e.g.
然后在另一个存储库中通过am
git 命令应用补丁,例如
git am -3 -k file.patch
See: man git-format-patch
and git-am
.