我在 fork 的 master 分支上所做的更改已合并到原始專案的 master 中(“將提交 95dd82b 合并到 tailwindlabs:master”)。我想為這個開源專案做出另一個貢獻。在 GitHub UI 中,我按下了“獲取和合并”按鈕。GitHub UI 仍然顯示訊息:“此分支比 tailwindlabs:master 提前 4 次提交”。如果我嘗試從這個分叉中做出另一個貢獻,這不會混淆嗎?我如何獲得與 tailwindlabs:master 的平等?
uj5u.com熱心網友回復:
您的
如您所見,早在 12 月 10 日,您將提交 (5d15) 直接添加到您自己的master. 然后,您在 12 月 13 日 (d309) 進行了進一步的提交。這些是您推送到拉取請求中的兩個提交。
現在讓我們看看您的拉取請求:

然而,我們注意到兩件事:
首先,這不是你的承諾!即使它與您的第一次提交具有相同的訊息,但它是不同的提交;它是 95dd,而您使用相同訊息的提交(在強制推送之后)是 5d15,而您的第二次提交是 d309。
其次,這不是合并!請注意,它只有一個父級(更新變更日志)。
所以你的提交沒有合并到尾風的master. 它被復制到了順風的master. 它是精心挑選的,根本沒有合并。可能順風在這里進行了所謂的擠壓和合并。這是處理來自一個 repo 的分叉版本的 PR 的可行策略,但是,盡管它的名字,它不是一個 merge,因此它隱藏了歷史——所以順風的人再一次沒有注意到你的分支是稱為master。
結果是您 master及其拓撲完全不受此事件的影響。您的分支從未合并到 tailwind 的master. 事實上,歷史上沒有任何內容將您的提交(5d15 和 d309)與 tailwind 的master.
好的,所以至少我們已經準備好回答你最初提出的問題了。您對狀態訊息感到困惑
This branch is 4 commits ahead of tailwindlabs:master
但這一點也不神秘,因為我們可以看到這 4 個提交是什么!它們是你曾經在你的master:

Those are your commits, and (wait for it...) there are four of them! Meanwhile you seem to think that some kind of synchronization should be taking place here, but of course it isn't, because your master is not tailwind's master.
What to do? Well, you should never have made changes directly on master to begin with, and the fact that the tailwind people failed to notice that you were making this mistake should have been another red flag for them:

But that's all water over the dam now. You must simply correct the situation at your end. The simplest way would be to delete your (evil) master entirely. But perhaps you would like to preserve your branch for historical purposes. Then just "park" the last "good" commit on that branch by giving it a branch name:
git switch -c my-accidental-evil-branch d3095c19
Fine. Now get rid of your evil local master:
git branch -D master
Now, if you'd like to start working another feature, do this:
Go to your repo at GitHub and update it from the upstream.
Return to your local repo and update it:
git fetch originNow make your feature branch!
git switch -c my-cool-feature origin/master
Now go forth and sin no more.
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/438246.html
