首页 > 解决方案 > git rebase(?) to upstream without merging?

问题描述

(Note: I strongly suspect my issue here is that I don't know what term to search for, it's very possible that the terms I'm using and what I actually want are different things. Pleas don't assuming too much based on the terms I used.)

Edit: All of the following is with regards to remote. (For the sake of discussion; assume that at the start, no local clients exist anywhere and, once I'm done, any local client created will be deleted.)

I created a fork, created a PR, that was merged into upstream and I attempted a rebase. But now when I look at the branches I intend to continue using (e.g. master), they show as being a merge of upstream/master and the stuff I did in my fork, and that despite having no changes that don't come from upstream.

What I want is to have my fork's master, when viewed on GitHub, reflect reality and show as having only upstream/master in its history. That is:

GitHub

If I didn't mind losing the rest of the history, I could accomplish this by deleting the entire repository and starting over, but that seems rather drastic for such a routine and necessary operation (and that won't work at all if I had other branches with ongoing work).

标签: gitgit-rebasegit-fork

解决方案


我想要的是让我的 fork 的主人,当在 GitHub 上查看时,反映现实并显示其历史中只有上游/主人

如果我理解正确,那不是现实。你的分叉的历史从你创建分叉的那一点开始,而不是从远程主控的位置开始。您的 fork 将永远与远程并行运行,并根据需要进行前向/后向合并。

当我git reset upstream/master ; git push origin master收到“更新被拒绝,因为您当前分支的尖端位于其远程对应部分之后”时。

简短的回答是,你可以完成你想要的git push origin master -f,有效地杀死你的分叉的历史,并扰乱可能在你的分叉上工作的其他人。

您所描述的听起来更像是您直接在遥控器上的贡献者所拥有的工作流程,为每个功能创建一个新分支。

我对上下文的理解: www.draw.io/制作的粗图

Top 是典型的 fork 工作流程,bottom 是如果您作为远程贡献者开发独立功能分支时所遵循的工作流程。在合并到远程之后,红色是分叉主节点上的(完全有效的)提交。


推荐阅读