这个问题引起的原因很简单,就是你不小心打包了 zip 在目录下,git push的 时候 zip超过100m变成大文件就导致了失败,那么以下是完整解决方案,本问题举一反三,任何git项目遇到这个问题报错均可通用
要解决这个问题,你需要从 Git 历史记录中删除这个大文件,然后再次推送你的更改。
以下是详细的步骤:
4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2
。git filter-repo
来从历史记录中删除这个文件。如果你还没有安装 git filter-repo
,可以通过以下命令安装:
pip install git-filter-repo然后,使用以下命令从历史记录中删除这个文件:
git filter-repo --path 4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2 --invert-paths
如果在第二步 遇到
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.
问题,那么是提示你需要新克隆
需要在一个新的克隆仓库上操作。让我们一步步来解决这个问题:
如果你跟卓伊凡一样,并不想移除原本的clone的文件,那么执行
如果你不愿意重新克隆一个仓库,我们可以使用 --force
选项来强制操作,不过请注意,这样可能会带来一些风险,尤其是如果你的项目涉及到其他协作者时,强制推送会重写公共历史,可能会导致其他人遇到冲突问题。
git filter-repo
移除大文件,并添加 --force
标志来强制操作。
git filter-repo --path 4e21e71a555febaa4dfaaa05cf7eeb606ea96ae2 --invert-paths --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项目遇到这个问题报错均可通用。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。