前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Git中一些报错的解决

Git中一些报错的解决

作者头像
夜梦星尘
发布2024-08-20 17:47:29
960
发布2024-08-20 17:47:29
举报
文章被收录于专栏:夜梦星尘的折腾日记

本文发布于390天前,最后更新于390天前,其中的信息可能有所发展或是发生改变。

参考文章:

error: failed to push some refs to ‘xxxx

场景

代码语言:javascript
复制
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 push -u origin 分支名,不妨尝试一下使用覆盖提交的方式 git push -f origin 分支名,其中“-f”是覆盖提交的参数。

如果需要,也可以先拉取代码,再推送代码:

先:git pull

后:git push

以上使用了强制push的方式提交代码,这样会带来版本覆盖的问题。比如:

fatal: refusing to merge unrelated histories

出错原因是两个仓库不同而导致的,需要在后面加上--allow-unrelated-histories进行允许合并,即可解决问题

完整代码如下:

代码语言:javascript
复制
#如果之前有初始化 init 需要删除
 
rm -rf .git
 
#初始化本地仓库(不要总是初始化)
 
git init
 
#连接远程git仓库
 
git remote add origin 仓库地址(注意是带有.git结尾的地址)
 
#创建并切到分支
git checkout -b 分支名
 
#添加本地需要提交的代码(.表示所有)
git add .
 
#提交代码并添加说明
git commit -m "说明内容"
 
#上传代码代码到分支(首次要先用git pull下拉代码)
git push origin 分支名

后记

当然,如果你想完全避免这个问题,新建一个仓库再上传就好啦

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-7-26 1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • error: failed to push some refs to ‘xxxx
  • fatal: refusing to merge unrelated histories
  • 后记
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档