git错误:无法将一些引用推送到
For some reason, I can't push now, whereas I could do it yesterday. 由于某种原因,我现在不能推动,而昨天却可以。 Maybe I
本文翻译自:git error: failed to push some refs to
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: 我的工作目录和远程存储库如下所示:
#1楼
参考:https://stackoom.com/question/1dBKO/git错误-无法将一些引用推送到
#2楼
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. 一个简单的git pull
就足够了。
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
). 这样,您将在新近更新的origin/master
(或origin/yourBranch
: git pull origin yourBranch
)之上重播( --rebase
部分)本地提交。
See a more complete example in the chapter 6 Pull with rebase of the Git Pocket Book . 请参阅《 Git Pocket Book的第6章重装基础》中的更完整示例。
I would recommend a: 我建议:
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 commit on 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
时的默认选项。
#3楼
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
#4楼
If you just used git init
and have added your files with git add .
如果您只是使用git init
并使用git add .
文件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 commit -m 'commit message'
任何内容( git commit -m 'commit message'
)以将其推送到远程...我只是遇到了这个错误,这就是我的问题。
#5楼
If you are using gerrit, this could be caused by an inappropriate Change-id in the commit. 如果使用的是gerrit,则可能是由于提交中的Change-id不正确所致。 Try deleting the Change-Id and see what happens. 尝试删除Change-Id,看看会发生什么。
#6楼
Remember to commit your changes before pushing to Github repo. 在推送到Github存储库之前,请记住先进行更改。 This might fix your problem. 这可能会解决您的问题。
更多推荐
所有评论(0)