3

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/*
4

2 回答 2

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会工作。

于 2013-01-12T09:22:52.170 回答
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以验证它是否符合您的预期。

于 2013-01-12T10:12:13.320 回答