我正在使用 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
orgit rebase
.
While you can override the remote by adding--force
to thepush
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说明如下:
这不是完全你的情况,但有助于了解什么是“快进”(分支的 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 upgitk --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/