我试图推动我的项目(所有文件在一个新的存储库)。我遵循这些步骤,但当我用git push -u origin master推时,我得到这个错误:

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:asantoya/projectnewbies.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.

我得到这个错误很多次,不知道该怎么做。


当前回答

! master -> master(非快进)

不要惊慌,这很容易解决。你所要做的就是发出一个拉,你的分支就会快进:

$ git pull myrepo master

然后重试你的推送,一切都会好起来的:

$ git推github master

其他回答

当我在开发分支和我的主分支没有最新更新时,这种情况发生在我身上。

所以当我试图从开发分支推git时,我遇到了这个错误。

我通过切换到主分支,git拉,然后回去开发分支和git推来修复它。

$ git fetch && git checkout master
$ git pull
$ git fetch && git checkout develop
$ git push

使用该命令:

Git pull——allow-unrelated-histories <存储库名称> <分支名称>

如:

Git pull -allow-unrelated-histories origin master

当项目没有任何共同祖先时,会发生此错误。

如果有人在尝试推到heroku时出现此错误,则只需将“origin”替换为“heroku” 是这样的: Git push -f heroku master

如果git pull没有帮助,那么可能你已经推送了你的更改(A),然后使用git commit -amend来添加更多的更改(B)。因此,git认为你可以丢失历史记录-它将B解释为不同的提交,尽管它包含了来自A的所有更改。

             B
            /
        ---X---A

如果A之后没人改变回购,你可以使用git push -force。

但是,如果A后面有其他人的变化:

             B
            /
        ---X---A---C

那么你必须将人从A变到B (C->D)。

             B---D
            /
        ---X---A---C

或者手动修复问题。我还没想过该怎么做。

试试这个命令:"git pull origin master"

这对我很管用。

查看这个链接:https://help.github.com/articles/dealing-with-non-fast-forward-errors