Git推送失败,“非快速更新被拒绝”

我通过Git Online编辑了我的GIT仓库。 我试图推动我的本地代码更改后,我得到一个错误:

Git push failed, To prevent from losing history, non-fast forward updates were rejected. 

我怎样才能解决这个问题?

首先拉改变:

 git pull origin branch_name 

如果您确定要推送,请将其添加到您的命令行中。 例如,使用git push origin --force (我推荐使用命令行,因为使用命令行可以find其他用户的更多支持,而SmartGit也可能无法使用这个function)。 help.github.com/remotes/

在推动之前,先用rebase选项做一个git pull。 这将得到您在网上(在您的起源)所做的更改,并在本地应用它们,然后在其上添加您的本地更改。

 git pull --rebase 

现在,您可以推送到远程

 git push 

有关更多信息,请参阅Git rebase说明和第3.6章Git分支 – 重新分配 。

我遇到了同样的错误,只需在命令中加上“–force”即可

 git push origin master --force 

我有同样的问题。
原因是,我的本地分行不知何故失去了跟踪对方的跟踪。

 git branch branch_name --set-upstream-to=origin/branch_name git pull 

并解决合并冲突,我才能够推动。

(一)Netbeans 7.1的解决scheme:试试拉。 这可能也会失败。 现在查看日志(通常现在在IDE中显示它们)。 有一行/多行说:

“由于此文件导致拉失败:”

search该文件,将其删除(之前进行备份)。 通常这是一个.gitignore文件,所以你不会删除代码。 重新推动。 一切都应该现在正常工作。

我也有同样的问题。 我解决了

 git checkout <name branch> git pull origin <name branch> git push origin <name branch> 

这是为我工作。 它可以在这里的 git文档中find

如果你在你想要的分支上,你可以这样做:

 git fetch origin # Fetches updates made to an online repository git merge origin YOUR_BRANCH_NAME # Merges updates made online with your local work