git - rebase废墟合并 [英] git - rebase ruins merge

查看:108
本文介绍了git - rebase废墟合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个独立的分支机构。我在一个月以上的不同时间对他们进行了研究。我通过检查合并一个分支(让我们称它为 apple )为另一个分支(让我们称它为 orange )橙和做 git merge --no-ff apple ,一切都很顺利。在gitk中,我可以清楚地看到每个分支都有自己的历史记录,并以橙色合并提交合并在一起。

后来我意识到橙色提交是不正确的,在构建过程中存在错误,我必须编辑橙色的提前提交。我使用 git rebase -i HEAD〜19 ,选择提交并将选取更改为编辑。所以我编辑提交,一切都很好,我完成了rebase。我回到gitk,两个分支的所有历史都是橙色的线性历史。

那么,我是否搞砸了一些东西呢,还是这样呢?我使用git reflog返回到合并时的状态,然后在橙色合并之前我再次执行了另一个复位操作,然后执行了rebase并修复了该提交,之后我进行了合并。现在一切看起来都是我所期望的,来自分支机构的提交不交错在一起。

为了将来的参考,有人可以告诉我如何在我已经合并到另一个分支的分支上重新提交提交,而不会以隔行提交(线性历史)结束?

如果我的术语不正确,请随时编辑。再次感谢

解决方案

这是rebase的预期行为。
它有效地重写了分支的历史,并导致它(默认)失去合并和其他元数据,留下一个简单直接的分支。



您可以使用

  git rebase --preserve-merges 

但将 - preserve-merges > - 交互式。仔细阅读。


I had two branches both independent. I worked on them at various points over a month. I went to merge one branch (let's call it apple) into the other (let's call it orange) by checking out orange and doing git merge --no-ff apple and everything went fine. In gitk I could clearly see the branches each had their own history and it was merged together in a merge commit on orange.

Later I realize that a commit in orange is incorrect, there is a mistake in the build process, and I must edit that early commit on orange. I use git rebase -i HEAD~19, choose the commit and change pick to edit. So I edit the commit and everything is fine, and I finish the rebase. I go back into gitk and all the history of the two branches is one linear history on orange.

So did I screw something up or is this the way it's supposed to be? I used git reflog to go back to when I did the merge, then I did another reset hard to go back to right before the merge on orange, then I did the rebase and fixed that commit, then after that I did the merge. Now everything looks the way I'd expect where the commits from the branches aren't interlaced together.

For future reference can someone tell me how I can rebase commits on a branch where I've merged in another branch, without ending up with interlaced commits (linear history)?

If my terminology isn't correct feel free to edit this. Thanks again

解决方案

This is expected behavior of rebase. It effectively re-writes the history of the branch, and that causes it to (default) lose merges and other meta-data, leaving a straight, simplified branch.

You can preserve merges by using

git rebase --preserve-merges

but there are some issues with combining --preserve-merges with --interactive. Tread carefully.

这篇关于git - rebase废墟合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆