简体   繁体   English

将多个分支合并为一个分支

[英]Merge multiple branches into a single one

Assuming I have branches o1 o2 o3 o4 . 假设我有分支o1 o2 o3 o4

They all have multiple commits where all commits in o1 were made before o2 which were made before o3 , etc... 他们都在那里所有提交多次提交o1是之前所做o2该日前作出o3 ,等...

I want to create a branch d1 which contains all commits from o1 , o2 , o3 and o4 intact. 我想创建一个分支d1 ,其中包含来自o1o2o3o4所有提交。 Ie same hash identifier. 即相同的哈希标识符。 You can assume that they do not conflict with each other. 您可以假定它们不会相互冲突。

The main purpose is that if they become merged to somewhere else in the project, no duplicate commits are detected (2 different commits with the same changes). 主要目的是,如果将它们合并到项目中的其他位置,则不会检测到重复的提交(具有相同更改的2个不同的提交)。

I'm puzzled trying to do this because git merge removes the branch after merging and it is the only thing I was able to think of and cherry-pick (if I understood right), doesn't seem to be a proper option. 我很困惑尝试这样做,因为git merge会在git merge删除分支,这是我唯一能想到的事情,而Cherry-pick(如果我理解正确的话)似乎不是一个合适的选择。

The only way you can create d1 without modifying the hashes is if you already have history that looks something like this: 无需修改哈希即可创建d1的唯一方法是,如果您已有类似以下内容的历史记录:

* -- * -- * -- * -- * -- * -- * -- * -- * -- * -- *
     o1             o2             o3             o4

That is, if everything you can reach from o1 is also reachable from o2 , etc. Otherwise, creating your branch d1 will involve creating at least one new commit from an old one, with the new one having a different parent. 也就是说,如果从o1可以到达的所有内容也可以从o2等到达。否则,创建分支d1将涉及从旧的提交中至少创建一个新的提交,而新的提交具有不同的父级。 The parent of a commit contributes to its hash, so what you want is not possible. 提交的父级会贡献其哈希,因此无法实现所需的内容。

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

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