当原始主分支无法合并时,是否有一个与原始存储库相匹配的分叉?

发布于 2024-10-11 22:38:48 字数 546 浏览 2 评论 0原文

SO 为我提供的相关问题仅回答可以通过拉动解决的简单情况 - 但是,这效果不佳,如下所示。

我分叉了一个存储库,只有一个 master 分支,我已经分叉了它,并且我在我的 master 和一个新分支中工作我自己的,rw-style。分叉存储库的所有者提交了我的一些更改,但没有提交其他更改;下面右上角的黑点代表来自我的 masterrw-style 分支的提交。

alt text

我知道使用 fork 队列不是一个好主意,所以我远离它。使用 git pull 确实有效,但它会产生一个我需要解决的冲突,并且还会导致我的 master 分支出现重复的历史记录,而这并不会看起来特别漂亮。

我现在不知道任何其他解决方案,所以我目前正在考虑从我尚未推送的两个提交创建一个补丁,删除我的分叉,从原始版本再次创建它,然后在上面应用我的补丁它的。

这是唯一的解决方案吗?

The related questions that SO offer me only answer simple cases that can be solved with a pull - however, that doesn't work well, as you'll see below.

There's a repository I've forked, with just a master branch, and I've forked it, and I've worked in both my master, and a new branch of my own, rw-style. The owner of the forked repository's committed some of my changes but not others; the black dots on the top right below represent commits from both my master and rw-style branches.

alt text

I'm aware using the fork queue is not a good idea, so I'm staying away from it. Using git pull does work, but it creates a conflict that I would then need to resolve, and it also results in duplicate history for my master branch, and that doesn't look particularly pretty.

I don't know any other solutions right now, so I'm currently considering just creating a patch from two commits that I haven't yet pushed, deleting my fork, creating it again from the original, and then applying my patches on top of it.

Is that the only solution?

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

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

发布评论

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

评论(1

夏日浅笑〃 2024-10-18 22:38:48

您可以通过以下方式将您的 fork 重新设置为 master:(

git rebase origin/master

在 fork 分支中时)。或者,您也可以将 --hard 您的 fork 分支重置为 master 分支,然后从您的 fork 分支中挑选每个提交(但是 rebase 的工作量将大大减少,除非您只被几个提交分叉)。

完成此操作后,您应该能够将分叉分支合并到主分支上,作为快进合并(没有合并提交或任何内容)。但是,执行上述任一操作都会弄乱 fork 分支中的所有哈希值,因此除非您确定没有其他东西引用该 fork 分支,否则不要这样做。

You can rebase your fork on to master, via:

git rebase origin/master

(while in the fork branch). Alternatively you could also reset --hard your fork branch to your master branch, then cherry-pick every commit from your fork branch back in (but the rebase will be wayyy less work unless you're only forked by a few commits).

Once you've done that, you should be able to just merge your forked branch on to the master branch, as a fast-forward merge (no merge commits or anything). However, doing either of the above will mess up all of your hashes in your fork branch, so don't do this unless you're sure nothing else is referencing the fork branch.

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