首页 > 解决方案 > 将 git 分支合并到另一个源

问题描述

我从 branch_1 创建了一个功能分支,然后从 branch_1 创建了 branch_1.1。现在我想将我的功能分支的更改合并到 branch_1.1,这样做的正确方法是什么?(我不介意将功能分支中的所有提交压缩为一个提交) 分支关系

标签: gitmergeversion-controlgit-merge

解决方案


假设现在的提交历史如下:

    master   branch_1
      |         |
...---A---...---B---...---C   branch_1.1
                 \            
                  D---...---E  feature

您可以通过以下方式直接合并feature分支branch_1.1

git checkout branch_1.1
git merge feature

提交历史将是:

    master   branch_1
      |         |
...---A---...---B---...---C---M  branch_1.1
                 \           /
                  D---...---E  feature

或者您可以与 squash 和 rebase 合并

git checkout feature
git pull origin branch_1.1 --rebase --squash
git checkout branch_1.1
git merge feature

提交历史将是:

    master   branch_1
      |         |
...---A---...---B---...---C---S  branch_1.1, feature

推荐阅读