我试图推动我的项目(所有文件在一个新的存储库)。我遵循这些步骤,但当我用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的推荐用法。这将覆盖远程上的更改。只有在100%确定本地更改应该推送到远程主服务器时才这样做。

⚠️试试这个:git push -f origin master

这是因为你在master中做了一些更改,所以项目要求你先拉。如果你想推它,你可以输入以下命令使用蛮力:

git push -f origin master

记得先提交你的修改:

git add .
git commit -m "Your commit message"

使用该命令:

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

如:

Git pull -allow-unrelated-histories origin master

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

我在github创建了新的回购,我有同样的问题,但它也有问题,而拉,所以这为我工作。

但在已经有很多这样的代码的回购中,不建议这样做 会把一切都搞砸

git push origin master --force

我唯一能够解决这个问题的是删除本地和git回购,并在两端重新创建相同的。目前还好。