git大文件上传问题
# 问题描述
使用git管理项目,其中包含超过了100MB的文件,上传github时超过了限制。
正好这个文件也不必上传,就从gitignore那里忽略了,但是提交时仍然显示超过限制。这是因为会扫描整个commit记录,其中已经有提交记录了。
# 解决方法
使用 git filter-repo 重写commit记录。删除对于这个大文件的追踪。
命令如下
# 打开 git bash ,运行下面命令即可
pip install git-filter-repo
# 安装后,重写对应文件的追踪
git filter-repo --force --invert-paths --path the/large/file
# 之后强制提交即可
git push -f origin main
# 如果还没将本地和远程仓库链接,运行下面命令
git remote add origin https://github.com/user_name/repository.git
git branch -M main
git push -u origin main
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# PS
也可以使用 git lfs 在一开始对大文件进行设置