git 错误:无法将一些引用推送到远程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24114676/
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 error: failed to push some refs to remote
提问by leipzy
For some reason, I can't push now, whereas I could do it yesterday. Maybe I messed up with configs or something.
出于某种原因,我现在不能推动,而我昨天可以。也许我搞砸了配置或其他东西。
This is what happens:
这是发生的事情:
When I use the git push origin master
当我使用 git push origin master
What my working directory and remote repository looks like:
我的工作目录和远程存储库是什么样的:
回答by VonC
If the GitHub repo has seen new commits pushed to it, while you were working locally, I would advise using:
如果 GitHub 存储库看到推送到它的新提交,而您在本地工作时,我建议使用:
git pull --rebase
git push
The full syntax is:
完整的语法是:
git pull --rebase origin master
git push origin master
With Git 2.6+(Sept. 2015), after having done (once)
使用 Git 2.6+(2015 年 9 月),完成后(一次)
git config --global pull.rebase true
git config --global rebase.autoStash true
A simple git pull
would be enough.
(Note: with Git 2.27 Q2 2020, a merge.autostash
is also available for your regular pull, without rebase)
一个简单的git pull
就足够了。
(注意:在Git 2.27 Q2 2020 中,amerge.autostash
也可用于您的常规拉取,无需变基)
That way, you would replay (the --rebase
part) your local commits on top of the newly updated origin/master
(or origin/yourBranch
: git pull origin yourBranch
).
这样,您将--rebase
在新更新的origin/master
(或origin/yourBranch
: git pull origin yourBranch
)之上重放(部分)您的本地提交。
See a more complete example in the chapter 6 Pull with rebaseof the Git Pocket Book.
请参阅Git Pocket Book的第 6 章 Pull with rebase中更完整的示例。
I would recommend a:
我会推荐一个:
# add and commit first
git push -u origin master
That would establish a tracking relationship between your local master branch and its upstream branch.
After that, any future push for that branch can be done with a simple:
这将在您的本地主分支与其上游分支之间建立跟踪关系。
之后,该分支的任何未来推送都可以通过简单的方式完成:
git push
See "Why do I need to explicitly push a new branch?".
请参阅“为什么我需要明确推送一个新分支?”。
Since the OP already reset and redone its commiton top of origin/master
:
由于OP已经复位,重做其承诺之上origin/master
:
git reset --mixed origin/master
git add .
git commit -m "This is a new commit for what I originally planned to be amended"
git push origin master
There is no need to pull --rebase
.
没有必要pull --rebase
。
Note: git reset --mixed origin/master
can also be written git reset origin/master
, since the --mixed
option is the default one when using git reset
.
注意:git reset --mixed origin/master
也可以写成git reset origin/master
,因为该--mixed
选项是使用时的默认选项git reset
。
回答by cagcak
Did anyone try:
有没有人尝试过:
git push -f origin master
That should solve the problem.
那应该可以解决问题。
EDIT:Based on @Mehdi ‘s comment below I need to clarify something about
—force pushing
. The git command above works safely only for the first commit. If there were already commits, pull requests or branches in previous, this resets all of it and set it from zero. If so, please refer @VonC ‘s detailed answer for better solution.
编辑:基于@Mehdi 在下面的评论,我需要澄清一些关于
—force pushing
. 上面的 git 命令仅适用于第一次提交。如果之前已经有提交、拉取请求或分支,这将重置所有这些并将其从零设置。如果是这样,请参阅@VonC 的详细答案以获得更好的解决方案。
回答by ironcladmvtm
If you just used git init
and have added your files with git add .
or something similar and have added your remote branch it might be that you just haven't committed (git commit -m 'commit message'
) anything locally to push to the remote... I just had this error and that was my issue.
如果您刚刚使用git init
并添加git add .
了类似的文件并添加了远程分支,则可能是您没有git commit -m 'commit message'
在本地提交 ( ) 任何内容来推送到远程...我刚刚遇到了这个错误,那是我的问题。
回答by ppmakeitcount
I had same problem. I was getting this problem because i had not made any commit not even initial commit and still i was trying to push.
我有同样的问题。我遇到了这个问题,因为我没有做出任何提交,甚至没有进行初始提交,但我仍然在尝试推送。
Once i did git commit -m "your msg"
and then everything worked fine.
一旦我做了git commit -m "your msg"
,然后一切正常。
回答by p8ul
Rename your branch and then push, e.g.:
重命名您的分支,然后推送,例如:
git branch -m new-name
git push -u new-name
This worked for me.
这对我有用。
回答by Sealter
I find the solution to this problem in github help.
我在 github 帮助中找到了这个问题的解决方案。
You can see it from:Dealing with non-fast-forward errors
你可以从:处理非快进错误
It says:
它说:
You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally:
您可以通过获取远程分支上所做的更改并将其与您在本地所做的更改合并来解决此问题:
$ git fetch origin
# Fetches updates made to an online repository
$ git merge origin branch
# Merges updates made online with your local work
Or, you can simply use git pull to perform both commands at once:
或者,您可以简单地使用 git pull 同时执行两个命令:
$ git pull origin branch
# Grabs online updates and merges them with your local work
回答by James Siva
git init
git remote add origin https://gitlab.com/crew-chief-systems/bot
git remote -v
(for checking current repository)git add -A
(add all files)git commit -m 'Added my project'
git pull --rebase origin master
git push origin master
git init
git remote add origin https://gitlab.com/crew-chief-systems/bot
git remote -v
(用于检查当前存储库)git add -A
(添加所有文件)git commit -m 'Added my project'
git pull --rebase origin master
git push origin master
回答by Divya
I had faced same problem,fixed with below steps .
我遇到了同样的问题,通过以下步骤修复。
git init
git add .
git commit -m 'Add your commit message'
git remote add origin https://[email protected]/User_name/sample.git
(Above url https://[email protected]/User_name/sample.gitrefers to your bit bucket project url )
git push -u origin master
git init
git add .
git commit -m 'Add your commit message'
git remote add origin https://[email protected]/User_name/sample.git
(上面的 url https://[email protected]/User_name/sample.git指的是你的比特桶项目 url )
git push -u origin master
hint
暗示
check if your git hub account link with your local git by using:
使用以下命令检查您的 git hub 帐户是否与本地 git 链接:
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
回答by Claw
Not commiting initial changes before pushing also causes the problem
在推送之前不提交初始更改也会导致问题
回答by Jim Sime
If you are using gerrit, this could be caused by an inappropriate Change-id in the commit. Try deleting the Change-Id and see what happens.
如果您使用的是 gerrit,这可能是由于提交中的 Change-id 不合适造成的。尝试删除 Change-Id,看看会发生什么。