问题:在修改完文件向github提交的时候,提交失败;由于之前直接在github上修改文件提交了一次,但是没有修改对,又再本地修改再次提交,就会失败,报如下错误:

hfzhang@010YS-IT-00368 MINGW64 /d/JAVA-01/JAVA-01/Week_07 (main)
$ git push origin
To github.com:areyoucreazy/JAVA-01.git! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'git@github.com:areyoucreazy/JAVA-01.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.

原因其实就是文件有冲突,没有解决的情况下直接提交造成的。

解决办法:

方案一:提交之前先执行 git pull 命令拉取代码,然后再提交,成功!

hfzhang@010YS-IT-00368 MINGW64 /d/JAVA-01/JAVA-01/Week_07 (main)
$ git pull
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 8 (delta 4), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (8/8), done.
From github.com:areyoucreazy/JAVA-01440448b..d51ef82  main       -> origin/main
Auto-merging Week_07/README.md
Merge made by the 'recursive' strategy.hfzhang@010YS-IT-00368 MINGW64 /d/JAVA-01/JAVA-01/Week_07 (main)
$ git push origin
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 591 bytes | 59.00 KiB/s, done.
Total 5 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), completed with 2 local objects.
To github.com:areyoucreazy/JAVA-01.gitd51ef82..16e6954  main -> main

方案二:这是从网上找的,使用的命令是 git pull origin master --allow-unrelated-histories,然后提交的时候用的命令是 git push -u origin master

我查了一下这个命令 --allow-unrelated-histories ,其实是提醒有两个不相干的分支要进行合并,并且强制执行的意思;如果方案一不成功,可以试试这个

git push 失败问题如何解决相关推荐

  1. Git push 失败:Empty reply from server 解决方法

    Git push 失败:Empty reply from server 解决方法 前脚和好友聊到他的 Git push 失败,后脚就轮到我了. 平台是Mac 最新10.14 Beta6 重启试了没用 ...

  2. git push 失败出现error: src refspec master does not match any.解决方案

    git push 失败出现error: src refspec master does not match any.解决方案 参考文章: (1)git push 失败出现error: src refs ...

  3. git push 失败,提示 unpack error/unpack failed 解决方法

    [问题描述] 在执行命令 git commit --amend 对提交进行修改后,再执行 git push review HEAD:refs/for/xxxx 将代码提交到 Gerrit 上,但是提交 ...

  4. git push 失败与解决方法

    今天想把最近的一些小代码push到github上 我先是将该目录git init进行初始化,然后 git add -A , 接着 git commit -m "description...& ...

  5. Git复习(五)之多人协作、git push失败、git pull失败

    多人协作 多人协作时,大家都会往master和dev分支上推送各自的修改. 现在,模拟一个你的小伙伴,可以在另一台电脑(注意要把SSH Key添加到GitHub)或者同一台电脑的另一个目录下克隆: $ ...

  6. git push时rejected,解决non-fast-forward errors的办法

    问题: 在git push时无法推送到远端仓库,出现下面的信息 $ git push origin master To https://github.com/USERNAME/REPOSITORY.g ...

  7. git push 失败,提示:error: RPC failed; HTTP 411 curl 22 The requested URL returned error: 411

    1.场景描述 因为某些原因,在家里用自己电脑工作了三天,其中前端项目中有几个宣传页,所以引入很多图片,还有一些依赖.在最后想要将代码 push 到远程仓库时,出问题了.在git add 和git co ...

  8. git push 失败的处理方式

    远程创建了含有Readme的仓库, 本地初始化并添加了远程仓库后, push却失败了, 出现提示: $ git push origin dev To https://git.oschina.net/e ...

  9. git push失败,报错fatal: does not appear to a git repository Could not read from remote repository

    我们在使用git的时候,git push会报错, $ git push -u origin master fatal: 'git@github.com/zejun_web' does not appe ...

最新文章

  1. ARKit从入门到精通-ARKit工作原理及流程介绍
  2. HTML的标签描述12
  3. python聚类分析如何确定分类个数_Python数据挖掘—聚类—KMeans划分法
  4. 机器学习知识点(六)增广矩阵求解拉格朗日乘子法的Java实现
  5. wordpress更新时需要ftp的解决方法
  6. JZOJ 5477. 【NOIP2017提高组正式赛】宝藏
  7. vuejs单文件组件:安装 webpack 和 vue-cli
  8. 【Tools】TeamViewer安装教程
  9. cytoscape操作经验
  10. CPU Cache对于并发编程的影响
  11. android The public type classname must be defined in its own file 报错
  12. 性能下降47%!华为、荣耀四款手机跑分作弊实锤,3DMark宣布榜单除名
  13. linux安装nfs服务器
  14. 寻求有用的Eclipse Java代码模板[关​​闭]
  15. Hibernate_01
  16. 【机器学习】竞争神经网络(Competitive Neural Network)的python实现
  17. [转]小D课堂 - 零基础入门SpringBoot2.X到实战_汇总
  18. 我在谷歌大脑工作的 18 个月中,是怎样研究强化学习的?
  19. 英伟达显卡老版本驱动下载网址
  20. ireport oracle,用ireport调用oracle存储过程

热门文章

  1. 商用向南,家用向北丨DOMOTEX asia 2020地毯馆大布局
  2. Codeforces1509.B. TMT Document
  3. 对待前任你有遗憾么?
  4. 初始圈的选择matlab,基于MATLAB的最优算法案例分析——关于徐州潘安湖风景区游览路线设计...
  5. 在Qt项目中添加pri文件
  6. vs2017或vs2019安装中Microsoft.VisualStudio.MinShell.Msi.Resources出错的问题
  7. 被误解的 Node.js
  8. Hadoop面试45个题目及答案
  9. 适合Linux系统的笔记本推荐,推荐5款让你的旧电脑重获新生的Linux发行版
  10. 2022-2028全球与中国消防无人机市场现状及未来发展趋势