git push origin master提交报错解决办法

╰半夏微凉° 2022-10-22 04:29 295阅读 0赞

使用git push origin master将本地提交推送到远程仓库的时候
遇到了这样的一个报错

  1. wangting@DESKTOP-O81VEVO MINGW64 ~/Desktop/wisdom_inventory_admin (master)
  2. $ git push origin master
  3. To https://gitee.com/wangyoko/wisdom_inventory_admin.git
  4. ! [rejected] master -> master (fetch first)
  5. error: failed to push some refs to 'https://gitee.com/wangyoko/wisdom_inventory_admin.git'
  6. hint: Updates were rejected because the remote contains work that you do
  7. hint: not have locally. This is usually caused by another repository pushing
  8. hint: to the same ref. You may want to first integrate the remote changes
  9. hint: (e.g., 'git pull ...') before pushing again.
  10. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

原因是远程仓库中的文件和我们本地的仓库有差异,例如你的远程仓库有个文件Readme. md,但是本地仓库却没有,就可能会出现这种情况。

本地仓库:

9baf628650d05c7ba9029673faf92fd5.png

远程仓库:

ec71ac504328ed60e1b892f45aa0fdf2.png

解决办法

  1. git pull origin master --allow-unrelated-histories

7520f9f945029a01bf8fa0db9e4ad1e6.png

将远程仓库的Readme. md一起拉下来同步到本地

再次执行
git push origin master

bdc6ac1a5820bd269ab4d19d4802eb3b.png

ok,远程仓库同步代码

eb533d1ba8336175e24132e9e1d19c1c.png

发表评论

表情:
评论列表 (有 0 条评论,295人围观)

还没有评论,来说两句吧...

相关阅读