“Git 推送非快进更新被拒绝”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4684352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does "Git push non-fast-forward updates were rejected" mean?
提问by Moshe
I'm using Git to manage my two computers and my development. I'm trying to commit changes to GitHub and I'm getting the error.
我正在使用 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.
无法将某些引用推送到
<repo>
。为了防止您丢失历史记录,非快进更新被拒绝。在再次推送之前合并远程更改。
What could be causing this and how can I fix this?
什么可能导致这种情况,我该如何解决?
EDIT:
编辑:
Pulling the repo returns the following:
拉取 repo 会返回以下内容:
*branch master->master (non-fast-forward) Already-up-to-date
*branch master->master(非快进)已经是最新的
Pushing still gives me the aforementioned error.
推动仍然给我上述错误。
采纳答案by VonC
GitHub has a nice section called "Dealing with “non-fast-forward” errors"
GitHub 有一个很好的部分叫做“处理“非快进”错误”
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 无法在不丢失提交的情况下对远程进行更改,因此它拒绝 push。
通常这是由另一个用户推送到同一分支引起的。您可以通过获取和合并远程分支来解决此问题,或者使用 pull 同时执行这两项操作。在其他情况下,此错误是使用
git commit --amend
或 之类的命令在本地进行破坏性更改的结果git rebase
。
虽然您可以通过添加--force
到push
命令来覆盖遥控器,但只有在您绝对确定这是您想要执行的操作时才应该这样做。
强制推送可能会给已经获取远程分支的其他用户带来问题,被认为是不好的做法。如有疑问,请不要强制推送。
Git cannot make changes on the remote like a fast-forward merge, which a Visual Git Referenceillustrates like:
Git 不能像快进合并那样在远程进行更改,Visual Git 参考说明如下:
This is not exactlyyour case, but helps to see what "fast-forward" is (where the HEAD
of a branch is simply moved to a new more recent commit).
这不完全是您的情况,但有助于了解“快进”是什么(HEAD
分支的 的 简单地移动到新的最近提交)。
The "branch master->master (non-fast-forward) Already-up-to-date
" is usually for local branches which don't track their remote counter-part.
See for instance this SO question "git pull says up-to-date but git push rejects non-fast forward".
Or the two branches are connected, but in disagreement with their respective history:
See "Never-ending GIT story - what am I doing wrong here?"
" branch master->master (non-fast-forward) Already-up-to-date
" 通常用于不跟踪其远程对应部分的本地分支机构。
例如,请参阅这个 SO 问题“ git pull 表示最新但 git push 拒绝非快进”。
或者两个分支是相连的,但与各自的历史不一致:
请参阅“永无止境的 GIT 故事 - 我在这里做错了什么?”
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.
这意味着你的 subversion 分支和你的远程 git master 分支在某些事情上不一致。
一些更改被推送/提交给一个不在另一个中的更改。
启动gitk --all
,它应该会给你一个关于哪里出错的线索——在历史中寻找“叉子”。
回答by minichate
It means that there have been other commits pushed to the remote repository that differ from your commits. You can usually solve this with a
这意味着有其他提交推送到远程存储库与您的提交不同。你通常可以用
git pull
before you push
在你推之前
Ultimately, "fast-forward" means that the commits can be applied directly on top of the working tree without requiring a merge.
最终,“快进”意味着提交可以直接应用在工作树的顶部,而无需合并。
回答by bdukes
A fast-forward update is where the only changes one one side are after the most recent commit on the other side, so there doesn't need to be any merging. This is saying that you need to merge your changes before you can push.
快进更新是一侧的唯一更改是在另一侧的最近一次提交之后,因此不需要进行任何合并。这就是说您需要先合并更改,然后才能推送。
回答by uspinar
you might want to use force with push operation in this case
在这种情况下,您可能希望对推操作使用力
git push origin master --force
git push origin master --force
回答by Abhishek Thomas
Never do a git -f
to do push
as it can result in later disastrous consequences.
永远不要做某事git -f
,push
因为它可能会导致以后的灾难性后果。
You just need to do a git pull
of your local branch.
你只需要做一个git pull
你当地的分支机构。
Ex:
前任:
git pull origin 'your_local_branch'
and then do a git push
然后做一个 git push
回答by Muhammad Soliman
You need to merge and resolve the conflicts locally
before you push your changes to remote repo/fork.
conflicts locally
在将更改推送到远程 repo/fork 之前,您需要合并并解决。
1) pull (fetch and merge)
1)拉(获取和合并)
$ git pull remote branch
2) Push the changes
2) 推送更改
$ git push remote branch
Still you have a quick choice to push
forcibly by using --force
option but should be avoided as it may result in changes loss or affect badly on other contributors.
您仍然可以快速选择push
强制使用--force
选项,但应该避免,因为它可能导致更改丢失或对其他贡献者产生严重影响。