如何删除 git 中的中间合并?
我想删除中间合并(删除,而不是挤压),然后将最后 2 次提交移到新分支。
这是我当前的 git log --graph :
* 3a5c453 - (2 hours ago) last commit (HEAD, master)
* b6c19f1 - (2 hours ago) Merge branch 'tade' into HEAD
|\
* | be356d0 - (2 hours ago) previous commit
| * 65328dc - (3 hours ago) some other commit in branch tade
我想以这样的结果结束:
* bbbbbbb - (some time in the future) a later commit on tade (tade)
* | aaaaaaa - (some time in the future) a later commit on master (master)
| * | 3a5c453 - (2 hours ago) last commit (HEAD, newone)
| * | be356d0 - (2 hours ago) previous commit
|/ |
| * 65328dc - (3 hours ago) some other commit in branch tade
我想到使用 git rebase -i 删除与分支tade的合并,然后执行gitbranchnewone
和gitreset --hard HEAD^2
将最后2次提交移动到新分支。当我进行 rebase 时,它向我显示了来自 tade 分支的所有提交,这些提交已合并到 master 和 | 中。不愿意删除它们。
有更好的方法还是我应该继续?
编辑:我更新了预期的状态图以使其更加清晰。 2 个新提交(aaaaaaa
和 bbbbbbb
)只是为了更好地说明状态(我希望)
I want to remove an in-between merge (remove, not squash) and then move the last 2 commits to a new branch.
This is my current git log --graph
:
* 3a5c453 - (2 hours ago) last commit (HEAD, master)
* b6c19f1 - (2 hours ago) Merge branch 'tade' into HEAD
|\
* | be356d0 - (2 hours ago) previous commit
| * 65328dc - (3 hours ago) some other commit in branch tade
I want to end up with this:
* bbbbbbb - (some time in the future) a later commit on tade (tade)
* | aaaaaaa - (some time in the future) a later commit on master (master)
| * | 3a5c453 - (2 hours ago) last commit (HEAD, newone)
| * | be356d0 - (2 hours ago) previous commit
|/ |
| * 65328dc - (3 hours ago) some other commit in branch tade
I thought of using git rebase -i
to remove the merge with the branch tade and then do a git branch newone
and git reset --hard HEAD^2
to move the last 2 commits to the new branch. When I did the rebase though, it showed me all the commits from the tade branch that got merged into master and | was reluctant in deleting them.
Is there a better way or should I go ahead with it?
EDIT: I updated the intended state graph to make it more clear. The 2 new commit (aaaaaaa
and bbbbbbb
) are only there to illustrate the state a little better (I hope)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用交互式变基在
be356d0
上变基3a5c453
,而不是合并提交b6c19f1
(即只需将3a5c453
提交移至向下)。然后你应该有这样的东西:然后你可以创建新的分支:
然后你可以删除
xxxxxx
并向 master 提交一些内容,最后得到这样的结果:Use interactive rebasing to rebase
3a5c453
onbe356d0
instead of the merge commitb6c19f1
(i.e. just move the3a5c453
commit one down). Then you should have something like this:Then you can just create new branches:
Then you can delete
xxxxxx
and commit something to the master and end up with this: