![](/img/trans.png)
[英]How can I create a sibling branch that includes all the commits from another branch into one node?
[英]How do I create a new branch cleaning up the commits from another branch?
我有两个分支, master
和feature
。
我完成了feature
的工作,所以这个分支有很多提交,但我不想按原样发布它。 我想创建一个名为feature_clean
的分支,其中包含来自feature
的所有修改,但具有更好的提交。
我尝试了以下方法:
git checkout -b feature_clean master
git checkout feature
git rebase --interactive feature_clean
# reorganize commits etc, save and close editor
,这创建了feature_clean
正确但它也修改了feature
。 事实上,两个分支是平等的。
我做错了什么? 我想暂时保留feature
(我稍后会在feature_clean
经过适当测试和批准后将其删除)。
您的变基命令错误;)您是在告诉 git 将当前分支( HEAD
,在这种情况下为feature
)变基在feature_clean
之上。 我认为你真正想做的是:
git checkout -b feature_clean feature
git rebase -i master
即在master
上重放feature_clean
的提交。 feature
仍将指向旧提交。
git rebase master
是git rebase --onto master master HEAD
的简写:获取master
和HEAD
之间的所有提交(可从HEAD
访问,但不能从master
访问)并将它们粘贴到master
签出您的功能分支git checkout feature
创建新的 feature_clean 分支git checkout -b feature_clean
将该分支重新定位到您从 master 中分离出来的位置git rebase -i --onto shaOfSplit shaOfSplit feature_clean
做你的交互式变基
在你的变基结束时,你将有两个从同一点断开的分支。 feature_clean
将是feature
的 rebase 版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.