当前位置: 首页 > news >正文

使用git提交时出现了报错,新手不会的可以参考一下。

使用git提交项目时遇到的问题

首先我新建了一个仓库,里面有gitnore这东西,本地的项目没有这东西,所以提交时会有冲突

执行正常步骤的命令

  1. 初始化本地 Git 仓库 在你的项目根目录(如 YY)打开终端,依次执行:

    git init

    git add .

    git commit -m "初始化项目"

  2. 关联远程仓库 在 Gitee 仓库页面找到“仓库地址”,如:

    Gitee - 基于 Git 的代码托管和研发协作平台你的用户名/仓库名.git

    在终端执行:

    git remote add origin Gitee - 基于 Git 的代码托管和研发协作平台你的用户名/仓库名.git

  3. 推送代码到 Gitee 执行:

    git push -u origin master

    (如提示分支为 main,则用 git push -u origin main

  4. 完善项目说明 在 Gitee 仓库页面,编辑 README.md,介绍项目功能和使用方法。

这里出现了报错

E:\学习资料\YY\Tools> git push -u origin master To https://gitee.com/lisusuyeye/pdf-batch-conversion.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://gitee.com/lisusuyeye/pdf-batch-conversion.git' hint: Updates were rejected because the remote contains work that you do not hint: have locally. This is usually caused by another repository pushing to hint: the same ref. If you want to integrate the remote changes, use hint: 'git pull' before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. PS E:\学习资料\YY\Tools>

你的推送被拒绝,是因为远程仓库有内容,你本地没有同步。解决方法如下:

  1. 先拉取远程内容并合并:

git pull origin master

如果有冲突,按提示解决冲突后,执行:

git add .

git commit -m "解决冲突"

  1. 再推送到远程仓库:

git push -u origin master

这样就可以把你的本地代码同步到 Gitee 仓库了。

还是不行

E:\学习资料\YY\Tools> git pull origin master remote: Enumerating objects: 4, done. remote: Counting objects: 100% (4/4), done. remote: Compressing objects: 100% (4/4), done. remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) Unpacking objects: 100% (4/4), 4.98 KiB | 254.00 KiB/s, done. From https://gitee.com/lisusuyeye/pdf-batch-conversion

  • branch master -> FETCH_HEAD

  • [new branch] master -> origin/master fatal: refusing to merge unrelated histories PS E:\学习资料\YY\Tools> git push -u origin master To https://gitee.com/lisusuyeye/pdf-batch-conversion.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://gitee.com/lisusuyeye/pdf-batch-conversion.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. If you want to integrate the remote changes, hint: use 'git pull' before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. PS E:\学习资料\YY\Tools>

依然是相同的报错

你的本地仓库和远程仓库历史不同步,导致无法合并和推送。请按以下步骤解决:

  1. 允许合并不相关历史:

git pull origin master --allow-unrelated-histories

如有冲突,按提示解决后:

git add .

git commit -m "合并远程仓库历史"

  1. 再次推送到远程仓库:

git push -u origin master

这样就能把你的本地内容和远程仓库合并并推送成功。

后面出现了一个vim界面,跟代码界面类似的界面

执行以下操作

处于 Git 合并提交信息编辑界面(通常是 Vim)。 此时你只需:

  1. 保存并退出编辑器

    • 如果是 Vim,按下 Esc,然后输入 :wq,再回车。

  2. 等待 Git 完成合并提交 合并完成后,你可以继续推送代码:

继续git push -u origin master

刷新Gitee界面,发现推送成功了

http://www.dtcms.com/a/306277.html

相关文章:

  • 技术复盘报告:Vue表格中多行文本字段数据保存丢失问题
  • 深入浅出设计模式——创建型模式之单例模式 Singleton
  • Docker离线安装依赖包地址
  • USRP捕获手机/路由器数据传输信号波形
  • Windows环境下安装Python和PyCharm
  • 【ip】IP地址能否直接填写255?
  • 【maven】仓库配置
  • 02 基于sklearn的机械学习-特征降维(特征选择、PCA)、KNN算法、模型选择与调优(交叉验证、朴素贝叶斯算法、拉普拉斯平滑)
  • 2507C++,介绍名字对象
  • Apache Ignite 集群状态(Cluster States)
  • fortigate的waf功能
  • openwrt中br-lan,eth0,eth0.1,eth0.2
  • day08(if-esle)
  • Linux 软件包管理
  • 【机器学习】机器学习新手入门概述
  • 基于C++的智能交通和智能公交流量预测与调度优化
  • 【物联网】基于树莓派的物联网开发【18】——树莓派安装Mosquitto服务
  • 【WPS】邮件合并教程\Excel批量写入数据进Word模板
  • 【0基础PS】PS工具详解--画笔工具
  • C++ 双缓冲(Double Buffering)实现无锁读取与高效数据更新
  • InfluxDB 与 Java 框架集成:Spring Boot 实战(二)
  • 用 Python 轻松实现时间序列预测:Darts 协变量 Covariates
  • 构建工具和脚手架:从源码到dist
  • uvm tlm preface
  • 若依前后端分离版学习笔记(四)——目录文件及主配置文件介绍
  • TP-Link Archer C50路由器曝安全漏洞,硬编码DES密钥可解密敏感配置
  • 用 Go Typed Client 快速上手 Elasticsearch —— 从建索引到聚合的完整实战
  • 基于 Hadoop 生态圈的数据仓库实践 —— OLAP 与数据可视化(一)
  • vscode配置rust环境
  • CVAE 回顾版