如何将 2 个不同的分支合并到 git,而不覆盖第一次提交所做的更改

How to merge 2 different branches into git, without overwriting changes made by the first commit

我有一个主分支 "Master",我从它创建了 2 个不同的分支,分别称为 "Branch-A" 和 "Branch-B"。分支用于两个不同的功能。完成 Branch-A 后,我将其合并回 Master。一切顺利。

现在我完成了 B 分支。我也想将其合并到 Master 中,但我知道 Branch-B 不包含我在 Branch-A 中创建的功能,该功能现在已合并到 Master 中。 git 是否会看到 Branch-B 就像代码已被改回(就像 Branch-A 合并到 Master 之前一样)并覆盖 Master 中 Branch-A 的更改?

希望我说清楚了。

不,不会。当您合并 branch-b 时,它会考虑来自 master(和 branch-A,因为它已经是 master 的一部分)和 branch-B 的所有更改。