与“git rebase”冲突

发布于 2024-09-13 20:24:06 字数 625 浏览 7 评论 0原文

所以,昨天我发布了一个问题当我尝试将上游分支重新设置为本地主题分支时,出现了一些奇怪的冲突。

最后我使用了 git rebase --merge upper 并解决了自上次 rebase 以来我没有触及过的文件中的许多冲突。

在这种情况下,我对变基的理解是,它将我的提交与该主题分支分离,应用来自上游分支的提交,然后将我的提交应用(作为补丁)在这些提交之上。因此,它最终成为一个快进操作。我不明白的是......为什么我会与来自上游的提交发生合并冲突。这些也作为补丁应用吗?我认为这只是......在来自同一分支的上一个提交之上“焊接”一些提交的行为?

我问这个问题是因为我在未触及的文件中存在很多冲突。哦,我每天都会与这个上游分支进行变基。

更新

我刚刚注意到从上游带到我的主题分支的一些提交的 SHA-1 id 已更改。有谁知道什么会导致 Git 这样做?可能是 --merge 开关吗?

我的git版本是1.5.6.5

So, yesterday I posted a question regarding some weird conflicts when I tried to rebase an upstream branch into my local topic branch.

In the end I used git rebase --merge upstream and solved a lot of conflicts in files I haven't touched since the previous rebase.

My understanding of rebase in such a case is that it detaches my commits from that topic branch, applies the commits from the upstream branch, and then applies (as patches) my commits on top of those. So, it ends up being a fast-forward operation. What I don't understand is... why would I have merge conflicts with those commits that come from upstream. Are those applied as patches as well? I thought is just... the act of "welding" some commits on top of the previous commit that came from the same branch?

I'm asking this because I had a lot of conflicts in files I haven't touched. Oh, and I do daily rebases with this upstream branch.

UPDATE

I've just noticed that some of the commits brought from the upstream to my topic branch have their SHA-1 id changed. Does anyone know what could cause Git do to this? Could it be the --merge switch?

My git version is 1.5.6.5

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

开始看清了 2024-09-20 20:24:06

Rebase 重写历史。如果你对已经推送到远程的提交进行变基,你就会进入一个受伤的世界。如果你继续这样变基,情况会更糟。 Rebase 有时有它的优势,但在我看来,它是一种特殊工具,而不是像合并那样的休闲工具。

然后将我的提交应用(作为补丁)。

是的,作为新提交

所以,它最终是一个快进操作

否。快进只是移动该分支的指针 HEAD 。您从远程引入新对象,然后在其上应用补丁。

如果您的本地和远程上次在 A1 同步,并假设您添加了(本地)A2A3 提交,并发现远程已添加 B1B2,变基将隐藏 A2A3,下拉 B1 > 和 B2 (应该快进,因为它们共享共同的后代 A1),然后为 A2应用补丁A3 作为新提交(因此是新的 SHA-1)A2'A3'

所以现在你的本地历史是:
A1 - B1 - B2 - A2' - A3'
这不是快进。

Rebase re-writes history. If you rebase commits that have already been pushed to a remote, you are entering a world of hurt. Even worse if you continue to rebase like this. Rebase has it's avantages at times, but it is a specialty tool IMO, not a casual tool, like merge.

and then applies (as patches) my commits on top of those.

Yes, as new commits

So, it ends up being a fast-forward operation

No. A fast-forward is simply moving the pointer HEAD of that branch. You are introducing new objects from remote and then applying patches on top of that.

If your local and remote were last in sync at A1, and say you added (locally) A2 and A3 commits, and found that the remote had added B1 and B2, rebasing will stash A2 and A3, pull down B1 and B2 (should be a fast-forward since they share a common descendant A1), and then apply patches for A2 and A3 as new commits (hence new SHA-1) A2' and A3'.

So now your local history is:
A1 - B1 - B2 - A2' - A3'
which is not a fast-forward.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文