git 通过将远程上的特定分支与特定的本地分支进行比较来创建补丁
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5432396/
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 a patch by comparing a specific branch on the remote with a specific local branch
提问by justify
I've been working with git for a few weeks, but now I'd like to contribute back to this open source project. I've merged my work with the latest, remote by pulling editing out conflicts and it all looks the way it should in gitk. Now I need to create a patch that is against the latest version of origin (remote) master. So I thought the following command would work:
我已经使用 git 工作了几个星期,但现在我想为这个开源项目做出贡献。我通过删除冲突将我的工作与最新的远程工作合并,并且在 gitk 中看起来一切正常。现在我需要创建一个针对最新版本的原始(远程)主服务器的补丁。所以我认为以下命令会起作用:
git format-patch origin:master --stdout > 25032011.patch
git format-patch origin:master --stdout > 25032011.patch
but I get:
但我得到:
fatal: Invalid object name 'origin'.
fatal: Invalid object name 'origin'.
So I've obviously got the command wrong. So how would I create a patch by comparing a specific branch on the remote with a specific local branch?
所以我显然得到了错误的命令。那么如何通过将远程上的特定分支与特定的本地分支进行比较来创建补丁?
回答by Rudi
Use git format-patch origin/master
. This creates a patch file for each commit on your checked out branch, which is not in origin/master.
使用git format-patch origin/master
. 这会为检出分支上的每个提交创建一个补丁文件,该分支不在 origin/master 中。
To have one file instead of multiple files you can use
要拥有一个文件而不是多个文件,您可以使用
git format-patch master --stdout > mypatch.patch
回答by batigolix
Use this to create one file containing all commits in your current branch that are not in the master branch:
使用它来创建一个包含当前分支中所有不在 master 分支中的提交的文件:
git format-patch master --stdout > mypatch.patch