首页 > 解决方案 > git rebase 并重置对源分支的提交

问题描述

我想改变我my-branchstaging-branch

A---B---C---D---E                  staging-branch
         \
          A5---A4---A3---A2---A1   my-branch

变基后,我想得到他们所有的提交,然后是我的。

A---B---C---D---E                            staging-branch
         
A---B---C---D---E---A5---A4---A3---A2---A1   my-branch

然后我想将所有提交合并为两个提交。

A---B---C---D---E---A11---A22   my-branch

我可以使用以下命令将所有提交分组为一个,但不确定如何将其分成两个。

git reset --soft HEAD~5
git commit --edit -m"A11"
git push origin my-branch

谢谢

标签: gitgithubgit-mergegit-rebasegit-merge-conflict

解决方案


您可以使用交互式 rebase根据您的逻辑对提交进行重新排序,并将它们压缩为两个单独的提交。整个事情看起来像这样

git checkout my-branch
git rebase staging-branch 
git rebase -i // reorder the commits and use squash to merge them and save the file


推荐阅读