即使在“git pull”之后,Git也会出现“非快进更新”错误

时间:2013-01-12 09:11:58

标签: git git-push fast-forward

Github是我项目的默认存储库(只是“origin”重命名为“github”)。发生了一些事情,以便“git push”导致“非快进更新”错误,即使“git push github master”有效。 “git pull”和“git pull github master”都表示最新状态。我怎样才能(a)确保Github上没有未更改的更改并且(b)更正非快进错误?

$ git status
# On branch master
nothing to commit (working directory clean)
$ git pull
Already up-to-date.
$ git pull github master
From github.com:MikeBlyth/mission_net
 * branch            master     -> FETCH_HEAD
Already up-to-date.
$ git push github master
Everything up-to-date
$ git push
To git@github.com:MikeBlyth/mission_net.git
 ! [rejected]        add_command -> add_command (non-fast-forward)
error: failed to push some refs to 'git@github.com:MikeBlyth/mission_net.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配置文件是

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
[remote "github"]
  url = git@github.com:MikeBlyth/mission_net.git
  fetch = +refs/heads/*:refs/remotes/github/*
[branch "master"]
  remote = github
  merge = refs/heads/master
[remote "heroku"]
  url = git@heroku.com:joslink.git
  fetch = +refs/heads/*:refs/remotes/heroku/*
  merge = refs/heads/master
[remote "heroku"]
url = git@heroku.com:joslink.git
fetch = +refs/heads/*:refs/remotes/heroku/*

2 个答案:

答案 0 :(得分:2)

说明可能与用于远程“github”的默认refspec相关:

+refs/heads/*:refs/remotes/github/*

一个简单的git push会推送:

  • 到与master关联的远程(此处为“github”),因为master是当前分支(根据git status
  • 所有其他分支(master add_command分支机构)

add_command是与github遥控器不同步的。

git checkout add_command 
git pull github

然后git push就可以了。

答案 1 :(得分:2)

'git push'的语法同时支持显式和简写版本。 显式版本git push github master适合您。简写版git push没有。

如果你使用速记版本,你不会告诉git使用什么遥控器以及将什么本地分支推到哪个远程分支。因此,git必须猜测你的意思。

您可以使用远程设置和push.default配置来配置:

   push.default
       Defines the action git push should take if no refspec is given on
       the command line, no refspec is configured in the remote, and no
       refspec is implied by any of the options given on the command line.
       Possible values are:

       ·    nothing - do not push anything.

       ·    matching - push all matching branches. All branches having the
           same name in both ends are considered to be matching. This is
           the default.

       ·    upstream - push the current branch to its upstream branch.

       ·    tracking - deprecated synonym for upstream.

       ·    current - push the current branch to a branch of the same
           name.

查看git branch -vv以查看当前分支跟踪的分支。然后检查git config --get push.default以确认它正在按预期执行。