使用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界面,发现推送成功了

相关推荐
挖掘狂人15 小时前
Git 从 0 到 1:用一个小项目走完 add / commit / reset / merge / rebase / push
git·后端·github
codigger16 小时前
Git 三区域模型:把 add、commit、reset、merge 一次讲透
git·github·编程·编程语言
水饺编程17 小时前
第1章:开发环境搭建,在 Windows 中安装 Git
linux·c语言·汇编·git·ubuntu
idanzk17 小时前
Git 推送 GitHub 报 SSL_READ /src refspec main 不匹配 完整踩坑记录
git·github·ssl
星恒随风19 小时前
Linux开发工具详解(二):Git版本控制、GitHub协作与GDB调试实战
linux·笔记·git·学习·github
寺中人2 天前
Xshell 完全入门指南:从安装到实战,远程连接+文件传输+会话管理全拆解
git·ssh·github·php·远程连接·xshell·运维工具
酬谢神明则必安2 天前
git学习记录01
linux·git·学习
lingchen19062 天前
版本控制 Git源代码项目管理
git
虫无涯2 天前
Coverity 如何结合 GJB8114-2013使用?
git·单元测试·嵌入式测试·coverity·静态扫描
喵本喵叁肆2 天前
Git 深度解读:从对象模型到分支指针,把版本控制的内核讲透
git