合并分支后无法推送到Git存储库

时间:2012-12-08 23:26:11

标签: git

我正在使用Git存储库,我有我的分支(称为jviotti),我的更改已合并到Master。 现在,在做出一些改变之后,我发现自己无法进入我的分支。

$ 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 pull:

$ 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.

在SO浏览类似问题后,我尝试了:

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

我认为这样可以解决问题。我错过了什么?

1 个答案:

答案 0 :(得分:3)

首先应确保您的本地分支机构的上游分支机构具有上游分支。

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 jviotti comments

  

我刚刚再次克隆了回购,改变了分支并且工作得很好   糟糕的git噩梦,一切都好了。