方案:使用git rebase和rebase.autoSquash进行分支合并
将主分支切换到分支A。
git checkout branch-A
从主分支pull最新更改。
git pull origin main
将主分支切换回主分支。
git checkout main
将分支A rebase到主分支。
git rebase branch-A
解决任何冲突,如果有冲突。
git mergetool
使用git add 暂存文件。
使用rebase-autoSquash自动合并分支A的提交到合并提交,并编辑合并消息。
git rebase -i --autosquash branch-A
7.使用 push 强制 push 合并提交。
git push origin main -f
这样,使用rebase-autoSquash可以按照commit 的时间基础进行分支合并,而且可以自动合并所有的提交。