为什么“git push”被拒绝?(“git pull”没有帮助)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8901973/
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
Why "git push" is rejected? ("git pull" doesn't help)
提问by Misha Moroshko
My current branch is my_branch
. Trying to push the changes to the remote repo I get:
我目前的分支是my_branch
. 尝试将更改推送到远程存储库,我得到:
$ git push
Counting objects: 544, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (465/465), done.
Writing objects: 100% (533/533), 2.04 MiB | 1.16 MiB/s, done.
Total 533 (delta 407), reused 0 (delta 0)
To [email protected]
4ed90a6..52673f3 my_branch -> my_branch
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]'
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.
Trying to git pull
results in:
试图git pull
导致:
$ git pull
Already up-to-date.
Why I get this error?
How could I resolve this problem and perform git push
successfully?
为什么我收到这个错误?我怎样才能解决这个问题并git push
成功执行?
回答by meagar
My current branch is my_branch.
我当前的分支是 my_branch。
That is your problem. When you pull, Git is telling you that your branch my_branch
is up to date, notmaster
, which is behind origin/master
making a fast-forward merge impossible.
那是你的问题。当您拉取时,Git 会告诉您您的分支my_branch
是最新的,而不是master
,这origin/master
导致无法进行快进合并。
In order to push master, you need to check out master
and pull. This will merge in the changes waiting on origin/master
and allow you to push your own changes.
为了push master,你需要check outmaster
和pull。这将合并等待的更改,origin/master
并允许您推送自己的更改。
git checkout master
git pull
# resolve conflicts, if any
git push
回答by The Nail
[If your master branch is already configured to rebase on pull, then you just need to do a pull on the master branch as is described in other answerd, but otherwise:]
[如果您的主分支已经配置为基于拉取,那么您只需要按照其他回答中的描述对主分支进行拉取,否则:]
If you get a non-fast-forward message, this means you can only push commits on top of the existing commits, but you're trying to do otherwise. Do a rebase on master before pushing (assuming the remote is called origin):
如果您收到非快进消息,这意味着您只能在现有提交之上推送提交,但您正在尝试做其他事情。在推送之前对 master 进行 rebase(假设远程称为 origin):
git checkout master
git pull --rebase origin master
git push
See also this question: git rebase and git push: non-fast forward, why use?
回答by Javad Nadery
change developer permission to "Maintainer"
将开发人员权限更改为“维护者”
回答by SwiftNinjaPro
what solved it for me:
是什么为我解决了这个问题:
go to https://github.com/settings/emails
去https://github.com/settings/emails
unckeck: "Block command line pushes that expose my email"
unckeck:“阻止暴露我的电子邮件的命令行推送”
the issue for me was: I had my email in the license
我的问题是:我在许可证中有我的电子邮件
回答by Olemak
It could also be a Git Hook!That would give the same error.
它也可能是一个 Git Hook!那会产生同样的错误。
Git Hooks run locally, so they can intercept and "pre-process" your commits before they are pushed.
Git Hooks 在本地运行,因此它们可以在推送之前拦截和“预处理”您的提交。
More on Git Hooks here: https://githooks.com/You should be able to find the hooks in the root of your repo, here: .git/hooks
.
Reading through the hook files may or may not not be helpful; they are full of advanced git commands and regexp.
Use File Explorer/Finder to look, as files prefixed by a period (.git, .gitignore) are often hidden in IDE's.
更多关于 Git Hooks 的信息在这里:https: //githooks.com/你应该能够在你的仓库的根目录中找到钩子,在这里:.git/hooks
。通读钩子文件可能有帮助也可能没有帮助;它们充满了高级 git 命令和正则表达式。使用文件资源管理器/查找器查看,因为以句点(.git、.gitignore)为前缀的文件通常隐藏在 IDE 中。
I got this same error when trying to push a branch called feature/JIRA-123_description-text
, and after some looking around I discovered that all the other project branches were named features/...
, so I was just missing an sin the word features. Renaming the branch fixed it.
我在尝试推送一个名为 的分支时遇到了同样的错误feature/JIRA-123_description-text
,经过一些环顾四周后,我发现所有其他项目分支都被命名为features/...
,所以我只是在 features 一词中缺少一个s。重命名分支修复了它。
So, in case pulling master etc does not fix the issue, try looking at some other branch names and match the format. Or check docs to see if there are special branch naming policies, or if you've tried to push something in the wrong file format et cetera.
因此,如果拉主等不能解决问题,请尝试查看其他一些分支名称并匹配格式。或者检查文档以查看是否有特殊的分支命名策略,或者您是否尝试以错误的文件格式等推送某些内容。