Git “fetch first”and ”non-fast-forward“ error when trying to push

转载请标明出处: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

关注我的公众号,轻松了解和学习更多技术
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值