2012-03-12 149 views
8

我實現了經典的OSS維護者/貢獻者git的工作流程,在github公司的項目,但是一個邊緣的情況下產生我不知道怎麼去解決一些奇怪的結果。git pull --rebase upstream&git push origin拒絕非快進?

比方說有,我分叉和上游添加遠程保持它最新的一個典型項目。

git clone [email protected]:kozhevnikov/<project>.git 
git remote add upstream [email protected]:<company>/<project>.git 

就這個例子而言,這個fork後面是一些提交。

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

我對這個工作叉,推動一些提交,推我的最後提交併創建一個pull請求更新我的叉子的克隆,以確保沒有衝突了。

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 [email protected]:kozhevnikov/<project>.git 
! [rejected]  master -> master (non-fast-forward) 
error: failed to push some refs to '[email protected]: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,充其量它會包括其他人的承諾進入我拉請求(來自復位),在最壞的情況它給了我合併衝突。

當我git push --force沒有任何pull--rebase它完美的作品,但是我在說給大家使用武力或使其成爲標準的工作流的一部分,我可以想象,沒有幾個人或一個小的工作小組合作,對單個感到非常不安叉和踩着對方的腳趾,用力推動。

任何想法?我錯過了什麼?

回答

16

當你

git pull --rebase upstream master 

你正在改寫自己的歷史,因爲你更新的上游資源庫基礎重建master分支。當你把你的rebased repo推到你的fork git抱怨。您需要推動與--force

git push --force origin master