git 使用之remote: File [4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2] size 104.090MB, exceeds quota 100MB remote: Please remove the file[s] from history and try again 报错如何解决-优雅草卓伊凡

简介: git 使用之remote: File [4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2] size 104.090MB, exceeds quota 100MB remote: Please remove the file[s] from history and try again 报错如何解决-优雅草卓伊凡

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
然后,使用以下命令从历史记录中删除这个文件:
    git filter-repo --path 4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2 --invert-paths
  1. 提交更改: 提交更改到你的仓库:
git add .
git commit -m "删除了大文件"
  1. 强制推送更改: 最后,强制推送更改到远程仓库:
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
  1. 重新克隆仓库: 克隆一个新的仓库,以便在干净的历史记录上工作。
git clone https://gitee.com/youyacao/www.youyacao.com.git
cd www.youyacao.com
  1. 移除大文件: 在新的克隆仓库中移除大文件。
git filter-repo --path 4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2 --invert-paths
  1. 提交更改: 提交更改到新的克隆仓库:
git add .
git commit -m "Remove large file from history"
  1. 强制推送更改: 最后,强制推送更改到远程仓库:
git push origin master --force

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

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

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

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

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

fatal: No configured push destination.

Either specify the URL from the command-line or configure a remote repository using

git remote add <name> <url>

and then push using the remote name

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项目遇到这个问题报错均可通用。


目录
相关文章
|
4月前
|
网络安全 开发工具 git
解决fatal:remote error:You can’t push to git://github.com/username/*.g
通过上述诊断与修复步骤,绝大多数的推送错误都能得到有效解决,确保您的Git工作流顺畅无阻。
333 1
|
6月前
|
Shell 网络安全 开发工具
fatal: unable to access 'https://github.com/wolfcw/libfaketime.git/': Encountered end of file
fatal: unable to access 'https://github.com/wolfcw/libfaketime.git/': Encountered end of file
|
8月前
|
开发工具 git
unable to index file ‘~$git提交版本号.xlsx‘
unable to index file ‘~$git提交版本号.xlsx‘
|
9月前
|
开发工具 git
*** Please tell me who you are.Run git config --global user.email “you@example.com“ git confi
*** Please tell me who you are.Run git config --global user.email “you@example.com“ git confi
|
9月前
|
存储 开发工具 git
解决“hint: the same ref. If you want to integrate the remote changes, usehint: ‘git pull‘ before pus”
解决“hint: the same ref. If you want to integrate the remote changes, usehint: ‘git pull‘ before pus”
212 3
|
10月前
|
移动开发 jenkins 持续交付
解决jenkins、git拉取代码仓库失败Please make sure you have the correct access rights
解决jenkins、git拉取代码仓库失败Please make sure you have the correct access rights
231 3
|
10月前
|
网络安全 数据安全/隐私保护
解决git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Pleas
解决git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Pleas
1707 0
|
10月前
|
开发工具 git
git报错 Unable to create ‘D:/project/xxx/.git/index.lock‘: File exists.
git报错 Unable to create ‘D:/project/xxx/.git/index.lock‘: File exists.
422 1
|
20小时前
|
人工智能 前端开发 Java
用git rebase命令合并开发阶段中多条commit提交记录
通过 `git rebase`,可以合并多个提交记录,使开发历史更简洁清晰。操作分为 6 步:查看提交历史 (`git log --oneline`)、设置需合并的提交数 (`git rebase -i HEAD~N`)、修改动作标识为 `s`(squash)、保存退出编辑、调整提交信息、强制推送至远程仓库 (`git push -f`)。此方法适合清理本地无关提交,但若有团队协作或冲突风险,需谨慎使用以避免问题。
|
4月前
|
开发工具 git
git 常用命令
这些只是 Git 命令的一部分,Git 还有许多其他命令和选项,可根据具体需求进行深入学习和使用。熟练掌握这些命令能够帮助你更高效地管理代码版本和协作开发。