简体   繁体   English

git cherry-pick 同一主控的两个分支之间所有缺失的提交

[英]git cherry-pick all missing commits between two branches from the same master

I have the following situation:我有以下情况:

two branches were created from master at different times两个分支是在不同时间从 master 创建的

    T0                T1
----+-----------------+------> master
    |                 |
    |                 |
    +---- BranchA     +---- BranchB

Development occurred on BranchA after time T0在时间 T0 之后在 BranchA 上进行开发

Some, but not all of those commits were merged in master after time T0, but before time T1一些但不是所有这些提交在时间 T0 之后但在时间 T1 之前合并到 master 中

I would like to now cherry-pick all the commits in BranchA that do not exist in BranchB into BranchB我现在想将 BranchA 中不存在于 BranchB 中的所有提交挑选到 BranchB 中

Untested, but未经测试,但是

git switch BranchB # Use git checkout BranchB if you prefer.
git cherry-pick ..BranchA

should work.应该管用。 Taken from the examples section of https://git-scm.com/docs/git-cherry-pick .取自https://git-scm.com/docs/git-cherry-pick的示例部分。

Instead of cherry picking, rebase.而不是樱桃采摘,变基。

First, rebase branchA onto master.首先,将 branchA 变基到 master 上。

This brings branchA up to date.这使 branchA 保持最新状态。 No question of what parts of branchA are in master.毫无疑问,branchA 的哪些部分在 master 中。 No question whether they're compatible with master.毫无疑问,它们是否与 master 兼容。

This will greatly simplify the process and give you an opportunity to resolve any conflicts between branchA and master without also involving branchB.这将大大简化流程,并让您有机会解决 branchA 和 master 之间的任何冲突,而无需涉及 branchB。

It's probably also a good idea to rebase branchB onto master just to make sure both branches are up to date and are working from a common base.将 branchB 变基到 master 可能也是一个好主意,以确保两个分支都是最新的并且在公共基础上工作。

Then rebase branchB onto branchA.然后将 branchB 变基到 branchA。 Or vice versa.或相反亦然。 Or cherry pick master..branchA (all the commits on branchA which are not in master) onto branchB.或者 cherry pick master..branchA(所有不在 master 中的 branchA 上的提交)到 branchB 上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM