转载请标明出处:http://blog.csdn.net/xx326664162/article/details/50016483 文章出自:薛瑄的博客
你也可以查看我的其他同类文章,也会让你有一定的收货!
一、”![rejected] master -> master (fetch first)”
解决办法:
执行命令 git fetch 拉取服务器上仓库
问题一的原因:
更新被拒绝,是因为本地库没有远程库的内容,通常是因为另外一个库push了相同的ref,你应该先合并远程库的改变,再次提交
Someone else (or you on some other machine) has pushed a changeset to the remote repository. You, on your local machine dont have those changes yet.
二、![rejected] master -> master (non-fast-forward)
解决办法:
执行命令”git pull origin master”
问题二原因:
本地的分支落后于远程的分支,需要先合并远程的改变,再push
I’ll provide an example and a picture to explain. Let’s assume your last pull from origin/branch was at Commit B. You have completed and committed some work (Commit C). At the same time, someone else has completed their work and pushed it to origin/branch (Commit D). There will need to be a merge between these two branches.
local branch: --- Commit C
/
/
/
origin/branch: Commit A ------ Commit B ---- Commit D
Because you are the one that wants to push, Git forces you to perform the merge. To do so, you must first pull the changes from origin/branch.
local branch: --- Commit C -- Commit E
/ /
/ /
/ /
origin/branch: Commit A ---- Commit B ---- Commit D
After completing the merge, you will now be allowed to fast-forward origin/branch to Commit E by pushing your changes.
我认为上面这两个原因本质是一样的:
按道理说原因是一样的,解决一个就都解决了,但是这两个会都先后出现,求高人指点
参考 http://my.oschina.net/juwenz/blog/153350?fromerr=KEvNlIqT
http://stackoverflow.com/questions/25862329/git-giving-fetch-first-error-when-trying-to-push
http://stackoverflow.com/questions/10298291/cannot-push-to-github-keeps-saying-need-merge
关注我的公众号,轻松了解和学习更多技术