簡體   English   中英

git pull --rebase upstream&git push origin拒絕非快進?

[英]git pull --rebase upstream & git push origin rejects non-fast-forward?

我已經為github上的公司項目實現了經典的OSS維護者/貢獻者git工作流,但是一個邊緣案例產生了一些奇怪的結果,我不知道如何解決。

讓我們說有一個典型的項目,我分叉並添加上游遠程,以使其保持最新。

git clone git@github.com:kozhevnikov/<project>.git
git remote add upstream git@github.com:<company>/<project>.git

出於這個例子的目的,這個fork后面有幾個提交。

git reset --hard HEAD~5 && git push --force

我在這個fork上工作並推送一些提交,然后再推送我的最后一次提交並創建一個pull請求我更新我的fork的克隆以確保沒有沖突。

touch foo && git add foo && git commit -m foo && git push
touch bar && git add bar && git commit -m bar

git pull --rebase upstream master

From github.com:<company>/<project>
 * branch            master     -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: foo
Applying: bar

現在,當我試圖推到我的叉子時,我被拒絕了。

git push

To git@github.com:kozhevnikov/<project>.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:kozhevnikov/<project>.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

接下來我該怎么辦? 我想要的只是拉請求包含foo和bar提交,但是......

當我pull ,拉請求包含重復的foo提交以及額外的合並提交。

git pull
Merge made by the 'recursive' strategy.

git push

在github上拉請求看起來像這樣。

Showing 4 unique commits by 1 author.
12345  
kozhevnikov  foo    4 minutes ago
67890  
kozhevnikov  foo    4 minutes ago
abcde  
kozhevnikov  bar    2 minutes ago
fghij  
kozhevnikov  Merge branch 'master' of github.com:kozhevnikov/<project>    just now

當我git pull --rebase而不是pull ,它最多會包含其他人的提交到我的pull請求(那些來自重置),最糟糕的是它給了我合並沖突。

當我git push --force沒有任何pull--rebase它完美地工作,但是我非常不安地說每個人都使用力量或使其成為標准工作流程的一部分,因為我可以想象很少人或小團隊合作一把叉子,用強制推動踩着對方的腳趾。

有任何想法嗎? 我錯過了什么?

當你

git pull --rebase upstream master

您正在重寫自己的歷史記錄,因為您在更新的上游存儲庫上重新設置了主分支。 當你把你的rebased repo推到你的fork git抱怨時。 你需要推動--force

git push --force origin master

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM