git 如何为分支中的所有提交生成补丁?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42800902/
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-09 04:52:35  来源:igfitidea点击:

How to generate patch for all commits in a branch?

gitgit-branchgit-patch

提问by akirekadu

How can I generate patch for all commits in a given branch by knowing only the branch name?

如何通过只知道分支名称为给定分支中的所有提交生成补丁?

This step is part of a complex workflow all of which is being automated. Hence requiring someone to manually determine the first commit in the branch is not an option.

此步骤是复杂工作流程的一部分,所有工作流程都将自动化。因此,要求某人手动确定分支中的第一次提交不是一种选择。

Note that anything relying on reflog is not an option either because changes in the branch are not made locally.

请注意,任何依赖于 reflog 的东西都不是一种选择,因为分支中的更改不是在本地进行的。

回答by VonC

If you know from which branch your "given branch" has been created, then making a patch is easy:

如果您知道您的“给定分支”是从哪个分支创建的,那么制作补丁很容易

git diff master Branch1 > ../patchfile
git checkout Branch2    
git apply ../patchfile

(and you can generate a patch applicable without git too)

(你也可以生成一个没有 git 也适用补丁

But finding the right "creation commit" of a branch can be complex: see "Finding a branch point with Git?"

但是找到分支的正确“创建提交”可能很复杂:请参阅“使用 Git 查找分支点?

The OP akirekaduused:

OP akirekadu使用:

git format-patch $(git merge-base --fork-point master)..branchB 

You can see it used in "git diffbetween working copy and branch base"

你可以看到它使用在“git diff工作副本和分支基地之间

legends2kadds in the comments:

Legends2k在评论中补充道:

One can verify the generated patch with git apply --stat patchfile
This won't apply, but give the details of the patch.

可以使用git apply --stat patchfile
This will not apply来验证生成的补丁,但提供补丁的详细信息。