git - push 超过100M
git - push 超过100M
error
remote: error: File: 526332dfc405e0709507c5d986b51ba0cf90f1d0 118.75 MB, exceeds 100.00 MB.
remote: Use command below to see the filename:
remote: git rev-list --objects --all | grep 526332dfc405e0709507c5d986b51ba0cf90f1d0
remote: Please remove the file from history and try again. (https://gitee.com/help/articles/4232)
To https://gitee.com/zc-lee/a-lee-markdown.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://gitee.com/zc-lee/a-lee-markdown.git'
解决
移除大文件
git rm --cache '大文件路径'
git commit --amend -CHEAD
git push
上传大文件
软件:Git Large File Storage
step
- Download and install the Git command line extension. Once downloaded and installed, set up Git LFS for your user account by running:
git lfs install
You only need to run this once per user account.
- In each Git repository where you want to use Git LFS, select the file types you'd like Git LFS to manage (or directly edit your .gitattributes). You can configure additional file extensions at anytime.
git lfs track "*.psd"
Now make sure .gitattributes is tracked:
git add .gitattributes
Note that defining the file types Git LFS should track will not, by itself, convert any pre-existing files to Git LFS, such as files on other branches or in your prior commit history. To do that, use the git lfs migrate[1] command, which has a range of options designed to suit various potential use cases.
- There is no step three. Just commit and push to GitHub as you normally would; for instance, if your current branch is named main:
git add file.psd
git commit -m "Add design file"
git push origin main
LFS仅支持付费企业中的存储库
WARNING: Authentication error: Authentication required: LFS only supported repository in paid enterprise.
batch response: LFS only supported repository in paid enterprise.
身份验证错误:需要身份验证:LFS仅支持付费企业中的存储库。
批量响应:LFS仅支持付费企业中的存储库。
rm .git/hooks/pre-push
git push -u origin "master"
仓库瘦身方案
查看存储库中的大文件
git rev-list --objects --all | grep -E `git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -10 | awk '{print$1}' | sed ':a;N;$!ba;s/\n/|/g'`
或
git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -15 | awk '{print$1}')"
改写历史,去除大文件
注意:下方命令中的 path/to/large/files 是大文件所在的路径,千万不要弄错!
git filter-branch --tree-filter 'rm -f path/to/large/files' --tag-name-filter cat -- --all
git push origin --tags --force
git push origin --all --force
如果在 git filter-branch
操作过程中遇到如下提示,需要在 git filter-branch
后面加上参数 -f
(出现这个错误的原因是,第一次操作成功后发现仓库大小并没有减少(可能还增大了),便进行了第二次操作)
Cannot create a new backup.
A previous backup already exists in refs/original/
Force overwriting the backup with -f
Lee2