5

我正在开发一个 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)

我认为这会奏效。我错过了什么?

4

1 回答 1

3

您首先应该确保您的本地分支有上游分支有它的上游。

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

那是因为新的默认推送策略将是 "simple"

一旦完成:

git pull --rebase origin jviotti

这可以在上面重播您的主历史记录origin/jviotti(如“引发冲突但没有发生冲突是什么意思git pullgit pull --rebase? ”)。

但在那之后,如“ git pull --rebase upstream&git push origin拒绝非快进? ”,你可能仍然需要:

git push --force origin jviotti

另一种选择是重置本地仓库,正如OP jviotti 评论的那样:

我刚刚再次克隆了 repo,更改了分支,效果很好。
可怕的 git 噩梦,现在一切正常。

于 2012-12-09T00:29:18.590 回答