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

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


当前回答

我通过以下步骤解决了这个问题:

git add *
git fetch
git pull origin main --allow-unrelated-histories or git pull --rebase <your_reponame> <your_branch>
git push -u "<pass your project clone url>" main or git pull origin [branch]

其他回答

这意味着您的远程git存储库配置为denynonfastforward = true。虽然很危险,但有时你可能真的需要覆盖git的历史记录(例如,在运行bfg——strip-blobs-big -than 100M之后),因此你可以临时将该设置修改为false (denynonfastforward = true,在your-repository.git/config中看到它),然后强制push(即git push -f)。

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

如果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 Totoise。 右击->TotoiseGit ->清理。 现在你可以推送到Github了 这对我很有效:D

这是因为您对它的主人进行了相互冲突的更改。你的存储库服务器不能用这些词告诉你,所以它给出了这个错误因为这不是他为你处理这些冲突的问题,所以他让你自己去做。是吗?

1- git拉 这将把您的代码从存储库合并到站点管理员的代码。 所以冲突就显现出来了。

2-处理这些手册冲突。

3-

git push origin master

瞬间,你的问题就解决了。