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

Git使用中遇到的问题(随时更新)

问题1.先创建本地库,后拉取远程仓库时上传失败的问题怎么解决?

操作主要步骤: 

        step1 设置远程仓库地址: 

        $ git remote add origin git@gitee.com:yourAccount/reponamexxx.git

        step2 推送到远程仓库:

        $ git push -u origin "master" 

报错信息:

To git@gitee.com:yourAccount/reponamexxx.git! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'gitee.com:yourAccount/reponamexxx.git'
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.

解决办法: 

         step1 拉取远程仓库,使用 --allow-unrelated-histories选项,本质上是合并(merge):

        $ git pull origin master --allow-unrelated-histories

        

        step2:在来一把,不带该选项。

        $ git pull origin master

         step3:推送

        $ git push -u origin "master"
        

        【注】如果是新建本地仓库,没有添加任何文件,只要使用如下语句就可以成功拉取。

        $ git pull origin master
 

问题2:如何在本地用命令行创建一个git仓库,并推送到远程?

操作主要步骤: 

        在本地用命令行创建一个git仓库,并推送到远程

        1. [ git init ]

        在gitStore目录下 初始化一个git仓库

        2. [ git add . ]   

        复制一个文件到gitStore目录下,然后执行[ git add . ]将“修改”从当前工作区存放到暂存区

        3. [ git commit -m "first commit" ]

        将暂存区中存放的文件提交到git仓库 

        4.在远端新建一个git代码库:https://github.com/*******

        5.git remote add origin https://github.com/********

        将本地代码库的当前分支与远程的代码库相关联

        6.[ git push -u origin master ]

        将本地代码库的当前分支推送到远程的代码库

问题3:一大堆文件中有个文件太大的导致上传失败怎么办?

        问题描述:

        一大堆文件上传,使用命令git push -u origin "master"后报错了,截图如下:        

        解决办法: 

        按照提示解决:

remote: error: File: a608078e6c02787b03158e5296ae238368d2fa1e 184.28 MB, exceeds 100.00 MB.
remote: Use command below to see the filename:
remote: git rev-list --objects --all | grep a608078e6c02787b03158e5296ae238368d2fa1e
remote: Please remove the file from history and try again. (https://gitee.com/help/articles/4232)

        1.查找大文件

        2.删除缓存的文件

        执行命令:

        git filter-branch -f --prune-empty --index-filter 'git rm -rf --cached --ignore-unmatch 安全/黑客大曝光(第7版).pdf' --tag-name-filter cat -- --all

        结果报错,原因是有特殊字符()。如下:

$ git filter-branch -f --prune-empty --index-filter 'git rm -rf --cached --ignore-unmatch 黑客大曝光(第7版).pdf' --tag-name-filter cat -- --all
WARNING: git-filter-branch has a glut of gotchas generating mangled historyrewrites.  Hit Ctrl-C before proceeding to abort, then use analternative filtering tool such as 'git filter-repo'(https://github.com/newren/git-filter-repo/) instead.  See thefilter-branch manual page for more details; to squelch this warning,set FILTER_BRANCH_SQUELCH_WARNING=1.
Proceeding with filter-branch...Rewrite de8e55eae6658a8a271604c05607a0a44a954c05 (1/4) (0 seconds passed, remaining 0 predicted)    D:/Apps/DevlopSoft/Git/mingw64/libexec/git-core\git-filter-branch: eval: line 439: syntax error near unexpected token `('
D:/Apps/DevlopSoft/Git/mingw64/libexec/git-core\git-filter-branch: eval: line 439: `git rm -rf --cached --ignore-unmatch 黑客大曝光(第7版).pdf'

        直觉可以用转义字符来解决,执行如下命令,果然可以。

$ git filter-branch -f --prune-empty --index-filter 'git rm -rf --cached --ignore-unmatch 黑客大曝光\(第7版\).pdf' --tag-name-filter cat -- --all

          3.重新推送

                 $ git push -u origin "master" --force

        

               还是推送失败怎么办?查询了下还是一样的。

         $ git rev-list --objects --all | grep a608078e6c02787b03158e5296ae238368d2fa1e  a608078e6c02787b03158e5296ae238368d2fa1e 安全/黑客大曝光(第7版).pdf        

        git 如何删除本地已经提交了的超过100M的文件

        要删除Git仓库中已经提交的大于100M的文件,你可以按照以下步骤操作:

  1. 找到提交记录中包含大文件的commit的哈希值。
  2. 使用git rm --cached命令从索引中移除大文件,但保留在本地磁盘上。
  3. 修改最近的提交以移除大文件。
  4. 强制推送到远程仓库。

        以下是具体的命令:

git log --oneline # 查找包含大文件的commit的哈希值
git rm --cached -r path_to_large_file # 将大文件从Git索引中移除
git commit --amend --no-edit # 修改最近的提交
git push origin your_branch_name --force # 强制推送到远程仓库

 

        git commit --amend --no-edit # 修改最近的提交 

 

         效果:

        如下图推送成功。

        

 

问题4:gitee单文件单库大小限制怎么办?

        单文件100M,单库500M限制,如果有需求,请参考如下解决办法: 

        参考:解决文件传输难题:如何绕过Gitee的100MB上传限制_gitee上传大于100m的文件-CSDN博客

http://www.lryc.cn/news/390271.html

相关文章:

  • php 跨域问题
  • 【leetcode52-55图论、56-63回溯】
  • 2024 年江西省研究生数学建模竞赛题目 A题交通信号灯管理---完整文章分享(仅供学习)
  • 日志可视化监控体系ElasticStack 8.X版本全链路实战
  • 【LinuxC语言】定义线程池结果
  • uniapp分包
  • Python 生成Md文件带超链 和 PDF文件 带分页显示内容
  • 行业模板|DataEase旅游行业大屏模板推荐
  • this.$refs[tab.$attrs.id].scrollIntoView is not a function
  • 【AI是在帮助开发者还是取代他们?】AI与开发者:合作与创新的未来
  • 【SpringBoot Web框架实战教程(开源)】01 使用 pom 方式创建 SpringBoot 第一个项目
  • Boosting【文献精读、翻译】
  • 保姆级教程|如何配置ROS1主从机
  • 贝叶斯优化算法(Bayesian Optimization)及其Python 和 MATLAB 实现
  • NLP - 基于bert预训练模型的文本多分类示例
  • 数据库备份和还原
  • 谷粒商城-个人笔记(集群部署篇一)
  • Linux环境下的字节对齐现象
  • 没有调用memcpy却报了undefined reference to memcpy错误
  • import和require的区别
  • 白骑士的Python教学高级篇 3.3 数据库编程
  • macOS 安装redis
  • 【AIGC评测体系】大模型评测指标集
  • 工厂模式之简单工厂模式
  • 2.(vue3.x+vite)调用iframe的方法(vue编码)
  • 实战项目——用Java实现图书管理系统
  • 利用DeepFlow解决APISIX故障诊断中的方向偏差问题
  • sqlalchemy获取数据条数
  • SpringBoot的自动配置核心原理及拓展点
  • 用随机森林算法进行的一次故障预测