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

相关推荐
渣渣小码11 小时前
GIT客户端配置支持中文
git·git中文显示
鄃鳕11 小时前
Git 拒绝 pull,本地有未提交的修改
git
Leslie_Lei15 小时前
【Eclipse】eclipse打开git拉取的项目
java·git·eclipse
渣渣小码18 小时前
GIT快速上手(常用指令)
git
会豪1 天前
Git命令-图解-小白专享
git
韦禾水1 天前
IntelliJ IDEA 2023更新git凭据
git·intellij idea
Yvonne爱编码1 天前
构建高效协作的桥梁:前后端衔接实践与接口文档规范详解
前端·git·ajax·webpack·node.js
@CLoudbays_Martin111 天前
CDN是否能有效检测并且同时防御Ddos 和 CC 攻击?
java·服务器·网络·数据库·git·数据库开发·时序数据库
oscar9992 天前
Monorepo 全面解析:优势、挑战与适用场景
git·monorepo
龙之叶2 天前
Git Commit 生成与合入 Patch 指南
git