当前位置:   article > 正文

使用GitHub push推送到远程仓库的时候报错 failed to push some refs to

使用GitHub push推送到远程仓库的时候报错 failed to push some refs to

使用GitHub push的时候报错

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/nat-weiting/snailshop.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

原因:
远程库的资源已经由你同一个团队的其他人员(有权限push到这个远程库的人)对资源进行了修改,也就是说,你本地库的资源已经落后于远程库,不是最新的了,这这样的情况下对未更新的地方做修改,GitHub是不允许此时再push的,等于你们产生了冲突
解决方法:
先把远程库的拉取到你本地仓库来,在最新的版本下进行修改以后,再次上传即可。
1.拉取(当然你也可以先fetch再merge):
git pull [远程库url] [分支名]
git pull origin master
查看你更新的文件内容 cat 文件夹名
发现如下为冲突表现
在这里插入图片描述
2.手动编辑冲突的地方,删除git给你在文件中警告的提示符号,至于内容得由你们去商量怎么改了

3.修改好后再次将修改的内容add、commit、 push

git add b.txt
git commit -m "resolve conflit" //注意解决冲突再次提交不要在后面加文件名
git push origin master
  • 1
  • 2
  • 3

成功

Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 553 bytes | 110.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To https://github.com/nat-weiting/snailshop.git
   d0ae636..e7d0c58  master -> master

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/445579
推荐阅读
相关标签
  

闽ICP备14008679号