前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >git 使用之remote: File [4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2] size 104.090MB, e

git 使用之remote: File [4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2] size 104.090MB, e

原创
作者头像
卓伊凡
发布2025-02-10 12:51:30
发布2025-02-10 12:51:30
18100
代码可运行
举报
文章被收录于专栏:git相关问题git相关问题
运行总次数:0
代码可运行

git 使用之remote: File [4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2] size 104.090MB, exceeds quota 100MB remote: Please remove the file[s] from history and try again To https://gitee.com/youyacao/www.youyacao.com.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to ‘https://gitee.com/youyacao/www.youyacao.com. git’ 报错如何解决-优雅草卓伊凡

问题原因

这个问题引起的原因很简单,就是你不小心打包了 zip 在目录下,git push的 时候 zip超过100m变成大文件就导致了失败,那么以下是完整解决方案,本问题举一反三,任何git项目遇到这个问题报错均可通用

解决方案

要解决这个问题,你需要从 Git 历史记录中删除这个大文件,然后再次推送你的更改。

以下是详细的步骤:

  1. 确认大文件: 首先,确认导致问题的大文件。你的错误信息中提到了这个文件 4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2
  2. 从历史记录中删除大文件: 你可以使用 git filter-repo 来从历史记录中删除这个文件。如果你还没有安装 git filter-repo,可以通过以下命令安装: pip install git-filter-repo
代码语言:javascript
代码运行次数:0
复制
然后,使用以下命令从历史记录中删除这个文件:

    git filter-repo --path 4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2 --invert-paths
  1. 提交更改: 提交更改到你的仓库: git add . git commit -m "删除了大文件"
  2. 强制推送更改: 最后,强制推送更改到远程仓库: git push origin master --force

如果在第二步 遇到

Aborting: Refusing to destructively overwrite repo history since this does not look like a fresh clone. (expected freshly packed repo) Please operate on a fresh clone instead. If you want to proceed anyway, use —force.

问题,那么是提示你需要新克隆

需要在一个新的克隆仓库上操作。让我们一步步来解决这个问题:

  1. 备份当前仓库: 首先,确保你的工作不会丢失。在另一个目录中备份当前仓库。 git clone https://gitee.com/youyacao/www.youyacao.com.git backup-repo
  2. 重新克隆仓库: 克隆一个新的仓库,以便在干净的历史记录上工作。 git clone https://gitee.com/youyacao/www.youyacao.com.git cd www.youyacao.com
  3. 移除大文件: 在新的克隆仓库中移除大文件。 git filter-repo --path 4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2 --invert-paths
  4. 提交更改: 提交更改到新的克隆仓库: git add . git commit -m "Remove large file from history"
  5. 强制推送更改: 最后,强制推送更改到远程仓库: git push origin master --force

如果你跟卓伊凡一样,并不想移除原本的clone的文件,那么执行

如果你不愿意重新克隆一个仓库,我们可以使用 --force 选项来强制操作,不过请注意,这样可能会带来一些风险,尤其是如果你的项目涉及到其他协作者时,强制推送会重写公共历史,可能会导致其他人遇到冲突问题。

  1. 移除大文件: 在当前仓库中使用 git filter-repo 移除大文件,并添加 --force 标志来强制操作。 git filter-repo --path 4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2 --invert-paths --force
  2. 提交更改: 提交更改到你的仓库: git add . git commit -m "Remove large file from history"
  3. 强制推送更改: 最后,强制推送更改到远程仓库: git push origin master --force

我们强制移除文件虽然会成功,但是会出现新的问题,

强制移除虽然成功了,新的报错来了

fatal: No configured push destination. Either specify the URL from the command-line or configure a remote repository using

代码语言:javascript
代码运行次数:0
复制
git remote add <name> <url>

and then push using the remote name

代码语言:javascript
代码运行次数:0
复制
git push <name>

不过这个就简单了吧,提示你的推送目的地尚未配置。你可以按照以下步骤来配置并推送代码

执行

git remote add origin https://gitee.com/youyacao/www.youyacao.com.git

又报错:

fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use git push —set-upstream origin master To have this happen automatically for branches without a tracking upstream, see ‘push.autoSetupRemote’ in ‘git help config’.

看来你的分支还没有设置上游分支。可以按照以下步骤操作:

设置上游分支并推送: 使用以下命令设置 master 分支的上游分支并推送更改:

git push --set-upstream origin master

这样,Git 会把你的 master 分支推送到远程仓库,并设置 master 作为上游分支。

确认推送: 确认推送成功后,你可以继续你原来的操作。

然后 如果还是有问题,请在移除大文件后,执行

git reset --hard HEAD

最终成功

请再次提交,如果还是 ,还是报错,那么备份出来 重新克隆!

所以啊 我们每天都要遇到无穷无尽的问题,只有学习才是最重要的,本问题举一反三,任何git项目遇到这个问题报错均可通用。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

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

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • git 使用之remote: File [4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2] size 104.090MB, exceeds quota 100MB remote: Please remove the file[s] from history and try again To https://gitee.com/youyacao/www.youyacao.com.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to ‘https://gitee.com/youyacao/www.youyacao.com. git’ 报错如何解决-优雅草卓伊凡
  • 问题原因
  • 解决方案
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档