2012-12-08 170 views
3

我正在使用Git存儲庫,我有我的分支(稱爲jviotti),我的更改已合併到Master中。 現在,在做出一些更改後,我發現自己無法推送到我的分支。合併分支後無法推送到Git存儲庫

$ git push origin jviotti 
To https://github.com/jorisbontje/pikapay-frontend.git 
! [rejected]  jviotti -> jviotti (non-fast-forward) 
error: failed to push some refs to 'https://github.com/jorisbontje/pikapay-frontend.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. 

我試圖再拉的git:

$ git pull 
You asked me to pull without telling me which branch you 
want to rebase against, and 'branch.jviotti.merge' in 
your configuration file does not tell me, either. Please 
specify which branch you want to use on the command line and 
try again (e.g. 'git pull <repository> <refspec>'). 
See git-pull(1) for details. 

If you often rebase against the same branch, you may want to 
use something like the following in your configuration file: 

    [branch "jviotti"] 
    remote = <nickname> 
    merge = <remote-ref> 
    rebase = true 

    [remote "<nickname>"] 
    url = <url> 
    fetch = <refspec> 

See git-config(1) for details. 

在所以在這裏瀏覽類似的問題後,我想:

$ git pull origin master:jviotti 
From https://github.com/jorisbontje/pikapay-frontend 
! [rejected]  master  -> jviotti (non-fast-forward) 

我認爲這會做的伎倆。我錯過了什麼?

+1

你試過''git pull origin jviotti''嗎? –

+0

當你做'git branch'時,你看到了什麼? –

回答

2

你應該首先確保你的本地分支有上游分支有它的上游。

git branch --set-upstream-to jviotti origin/jviotti 
# or 
git branch -u jviotti origin/jviotti 

那是因爲新的默認push policy will be "simple"

一旦做到這一點:

git pull --rebase origin jviotti 

,可以重播在origin/jviotti頂部你主人的歷史(如 「What does it mean when git pull causes a conflict but git pull --rebase doesn't?」)。

但在那之後,在 「git pull --rebase upstream & git push origin rejects non-fast-forward?」,你可能仍然需要一個:

git push --force origin jviotti 

另一種選擇是可以重置本地回購,作爲OP jviotticomments

我剛剛克隆了回購,更改分支和它很好。
Awfull git惡夢,一切都好了。

+0

它看起來像他在上游'jviotti'上使用本地'master' - 這可能嗎? –

+0

@EricWalker不在第一推:'jviotti - > jviotti(非快進)'意味着本地'jviotti'已經分化。我確信本地分支有正確的上游分支。我同意'git pull origin master:jviotti'看起來很陰暗,但可能會受到另一個SO回答過於緊張的啓發。 – VonC

+0

嗯,我沒有git pull --rebase的起源jviotti,它的工作,但它在我的代碼中插入奇怪的字符,並打破了一切。然後,我再次克隆了回購,更換分支,它工作得很好。 Awfull git噩夢,一切都好了。謝謝 – jviotti