Git报告在推送时失败,但提交更改

时间:2014-07-24 09:02:54

标签: git git-branch git-push git-pull

在git上尝试 git push 我的更改时,出现以下错误:

To $gitRepo
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to $gitRepo
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  

此分支没有任何修改(我是唯一一个正在进行修改的人)。所以我真的不应该得到非快进错误。

当我 git pull 时,我得到:

You asked me to pull without telling me which branch you
want to merge with, and 'branch.$myCurrentBranch.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.

我确实在$ myCurrentBranch上,因为 git status 确认了它。

有趣的是,更改已注册(使用 git log 和存储库进行检查)。

您对我收到这些错误有什么想法吗?

2 个答案:

答案 0 :(得分:1)

检查您的.git/config文件是否有以下条目。如果没有,您需要添加它:

[branch "master"]
    remote = origin
    merge = refs/heads/master

这表明,当您在分支主数据上执行git pull时,它将与refs/heads/master合并。

答案 1 :(得分:0)

首先,你有没有推动过你的主人,然后重新定位你当地的主人?如果您在项目中独自一人,这可能会解释错误。

对于第二个,你的分支似乎与远程分支无关。 Setting an upsteam branch可能会对您有所帮助。

如果您的问题不同,可以添加本地和远程分支的一些提交日志,以便我们更清楚地了解发生了什么吗?