git - "Git push non-fast-forward updates were rejected"是什么意思?

标签 git version-control

我正在使用 Git 来管理我的两台计算机和我的开发。我正在尝试将更改提交到 GitHub,但出现此错误:

Failed to push some refs to <repo>. To prevent you from losing history, non-fast-forward updates were rejected. Merge remote changes before pushing again.

可能是什么原因造成的,我该如何解决?

编辑:

pull repo 返回以下内容:

*branch master->master (non-fast-forward) Already-up-to-date

推送仍然给我上述错误。

最佳答案

GitHub 有一个很好的部分叫做“Dealing with “non-fast-forward” errors

This error can be a bit overwhelming at first, do not fear.
Simply put, git cannot make the change on the remote without losing commits, so it refuses the push.
Usually this is caused by another user pushing to the same branch. You can remedy this by fetching and merging the remote branch, or using pull to perform both at once.

In other cases this error is a result of destructive changes made locally by using commands like git commit --amend or git rebase.
While you can override the remote by adding --force to the push command, you should only do so if you are absolutely certain this is what you want to do.
Force-pushes can cause issues for other users that have fetched the remote branch, and is considered bad practice. When in doubt, don’t force-push.


Git 无法像快进 merge 那样在远程进行更改,这是 Visual Git Reference说明如下:

alt text

这不是完全你的情况,但有助于了解什么是“快进”(分支的 HEAD 只是简单地移动到一个新的更新的提交)。


branch master->master (non-fast-forward) Already-up-to-date”通常用于不跟踪它们的本地分支远程对应。
例如,参见这个 SO 问题“git pull says up-to-date but git push rejects non-fast forward”。
或者这两个分支是相连的,但与它们各自的历史不一致:
参见“Never-ending GIT story - what am I doing wrong here?

This means that your subversion branch and your remote git master branch do not agree on something.
Some change was pushed/committed to one that is not in the other.
Fire up gitk --all, and it should give you a clue as to what went wrong - look for "forks" in the history.

关于git - "Git push non-fast-forward updates were rejected"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4684352/

相关文章:

git 删除以冒号开头的文件

Git rebase 一个分支到 master 失败,如何解决?

git - 如何删除 "fatal: loose object"?

git - 如何为 "git add -p"中的帅哥设置制表符大小?

Git 智能 HTTP 协议(protocol)无法在推送时执行服务器端 Hook

由于更改了文件,Git 不会 pull

git - 在多次错误提交后 merge 分支

svn - 如何在 TortoiseSVN 中取消忽略文件?

svn - 当修订跨分支重叠时,使用 svn log 提取标签之间的提交消息

svn - 您应该在代码和变更日志中评论更改吗?