git:恢复合并提交,但保存保存后续提交(在删除合并提交之后)



一个两周前的branch'branch-One'(是在两个蒙特人之前创建的,包含了很多旧代码(,并将其合并到'master'中,并且此提案具有名称'commit's Commit123'。合并团队工作并做出了很多投入。需要删除此合并,但保存后续提交。

我看到解决方案:在随后的提交中添加后,恢复合并提交,但这是很长的解决方案。

有人可以提出太多乐观和简短的解决方案吗?

如果您没有问题重写历史记录,请摆脱历史记录的合并并在其之后重播历史记录。让我们称之为修订 Merge-Rev

git checkout merge-rev~1 # right before the revision you want to get rid of
git cherry-pick merge-rev..master # linear history between merge and master (not including the merge you want to get rid). Adjust if the branch is not master
# if you like the results
git branch -f master
git push -f some-remote master # if you need to push somewhere to replace the old branch

这是假设历史是在您想摆脱的合并之后是线性的。

$ git fetch
$ git checkout commit123 # the merge revision you want to get rid of
$ git reset --soft <the-commit-on-master-before-the-merge>
$ git commit -m 'squashed commit123'
$ git checkout origin/master
$ git revert <squashed-commit123>

挤压提交的内容与合并具有相同的内容,但更容易恢复主。

最新更新