<分区>
我的仓库有一个分支和许多不同的提交。初始提交包含一些代码。我想创建当前分支的 pull 请求,但要创建较早版本然后是初始提交,以便我可以查看已添加的整个相关代码。如何将一个提交拆分为 2 个?
标签 git
<分区>
我的仓库有一个分支和许多不同的提交。初始提交包含一些代码。我想创建当前分支的 pull 请求,但要创建较早版本然后是初始提交,以便我可以查看已添加的整个相关代码。如何将一个提交拆分为 2 个?
最佳答案
您可以按照 this answer 中描述的过程进行操作至 "How to break a previous commit into multiple commits"除了您需要添加 --root
开关之外,因为您想要修改分支中的第一个提交。
来自 the documentation :
--root
Rebase all commits reachable from <branch>, instead of limiting them with an <upstream>. This allows you to rebase the root commit(s) on a branch.
例如,假设你想修改 master
中的初始提交,你会说:
git checkout master
git rebase -i --root
关于Git 将初始提交拆分为 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41375681/