Git:虽然我已经完成了 git pull,但未能推送一些参考
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7228715/
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
Git: failed to push some refs although I have done git pull
提问by jjei
I started to get 'failed to push some refs' error when I changed some files and tried to do push. Most instructions tell to do git pull first. I have done it and git says everything is up to date. Any idea how to solve the error? I also started getting 'no version information available' message, I don't know does that have anything to do with the error.
当我更改一些文件并尝试推送时,我开始出现“无法推送一些引用”错误。大多数指令都告诉先做 git pull 。我已经完成了,git 说一切都是最新的。知道如何解决错误吗?我也开始收到“没有可用的版本信息”消息,我不知道这与错误有什么关系。
git push origin master
git: /usr/local/lib/libz.so.1: no version information available (required by git)
Enter passphrase for key '/root/.ssh/id_rsa':
To git@[mydomain].beanstalkapp.com:/repo-git.git
! [rejected] master -> master (non-fast forward)
error: failed to push some refs to 'git@[mydomain].beanstalkapp.com:/repo-git.git'
回答by Sylvain Defresne
The error is that somebody else has pushed in the master
branch and you would overwrite their change if git
allowed you to push (this is what non-fast forward
error means). So you need to merge your local master
branch with the remote master
branch.
错误是其他人已在master
分支中推送,如果git
允许您推送,您将覆盖他们的更改(这就是non-fast forward
错误的含义)。因此,您需要将本地master
分支与远程master
分支合并。
This can happen if you did the git pull
while the local branch was not the master
branch. If you only want to push the branch you are working on and not the master
branch, you need to tell it to git
using the complete form of git-push
:
如果您git pull
在本地分支不是master
分支时执行此操作,则可能会发生这种情况。如果你只想推送你正在处理的master
分支而不是分支,你需要告诉它git
使用完整的形式git-push
:
$ git push remote local-branch:remote-branch
回答by Gaurav Agarwal
The best possible answer is on Git help here
最好的答案是这里的Git 帮助
Dealing with non-fast-forward errors
处理非快进错误
From time to time, you may encounter this error while pushing commits (git push origin master
) to GitHub:
有时,您在将提交 ( git push origin master
)推送到 GitHub时可能会遇到此错误:
To https://github.com/user/repo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/user/repo.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.
This error can be a bit overwhelming at first; do not fear!
这个错误一开始可能有点让人不知所措;不要害怕!
Simply put, Git can't 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.
简而言之,Git 无法在不丢失提交的情况下对远程进行更改,因此它拒绝推送。通常,这是由另一个用户推送到同一分支引起的。
You can remedy this by fetching and merging the remote branch:
您可以通过获取和合并远程分支来解决此问题:
git fetch origin
git merge origin master
Or, you can simply use git pull to perform both commands at once:
或者,您可以简单地使用 git pull 同时执行两个命令:
git pull origin master
In some 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 commit --amend
或 之类的命令在本地进行破坏性更改的结果git rebase
。虽然您可以通过向 push 命令添加 --force 来覆盖远程,但只有在您绝对确定这是您想要执行的操作时才应该这样做。强制推送可能会给已经获取远程分支的其他用户带来问题,被认为是不好的做法。如有疑问,请不要强行推动。
回答by Aliaksei
Be sure your branch is unprotected, or developer can push is checked.
确保您的分支不受保护,或者检查开发人员可以推送。
回答by geneorama
Also, the error happens when you put the wrong branch name into your push command.
此外,当您将错误的分支名称放入 push 命令时会发生错误。
For example, say you're on a branch called iss8
, but you tell git to push to iss3
(like I just did), you'll get the same error.
例如,假设您在一个名为 的分支上iss8
,但是您告诉 git 推送到iss3
(就像我刚刚所做的那样),您将得到相同的错误。
$ git push origin iss3
error: src refspec iss3 does not match any.
error: failed to push some refs to '[email protected]:myuser/myproject.git'
Hmm, check status:
嗯,检查状态:
$ git status
On branch iss8
nothing to commit, working directory clean
Oh, look, I'm on a different branch. Thanks git for not letting me do something really dumb.
哦,看,我在不同的分支上。感谢 git 没有让我做一些非常愚蠢的事情。
$ git push origin iss8
Counting objects: 15, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 2.62 KiB | 0 bytes/s, done.
Total 9 (delta 3), reused 0 (delta 0)
To [email protected]:myuser/myproject.git
* [new branch] iss8 -> iss8
回答by James Lawruk
Be sure to verify that the pull actually worked. It is possible the merge (which is part of a pull) failed.
一定要验证拉动确实有效。合并(这是拉动的一部分)可能失败。
When I had this error message I failed to notice the pull failed. The pull failed due to some uncommitted file changes (unrelated to the files I was trying to push) which caused the merge to fail. I reverted those file changes (because they were not important) and then did a pull again. After the successful pull, the push worked.
当我收到此错误消息时,我没有注意到拉取失败。由于一些未提交的文件更改(与我尝试推送的文件无关)导致合并失败,因此拉取失败。我恢复了这些文件更改(因为它们不重要),然后再次拉动。拉动成功后,推送成功。
回答by Gene
回答by Codelover
try this command git push -f origin master
试试这个命令 git push -f origin master