我试图推动我的项目(所有文件在一个新的存储库)。我遵循这些步骤,但当我用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.

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


当前回答

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

其他回答

我也得到了同样的错误,但我很容易解决它通过获取其url 作为

git fetch origin Your repository origin

然后简单地应用命令

git push -f origin master

你会得到一个好结果

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

这对我很管用。

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

我的遥控器不与本地同步,所以这对我来说很有效

git pull --rebase

并确保当你再次拉git时,它应该说Already up to date 现在你可以推到原点了

假设你已经有git远程添加源远程存储库URL

do

git push origin master

截图说明了一切

或者你也可以这样做

Git存储(暂时存储未提交的工作) Git pull(使本地和远程同步) Git stash pop(返回你未提交的更改) git推

警告:

去“git拉”并不总是一个解决方案,所以要小心。如果您有意更改了存储库历史,您可能会面临这个问题(在Q中提到的问题)。在这种情况下,git会混淆远程回购中的历史更改和新更改。所以,你应该使用git push -force,因为调用git pull会撤销你故意对历史记录所做的所有更改。

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