自动摘要
正在生成中……
从coding 切换仓库到github,执行推送时发现失败。
git push -u origin stable
部分错误如下
remote: error: Trace: 5d92ae3dc6944d8e566d2caba50b0eb56422a576cae08f5fa302451bf24fc037
remote: error: See https://gh.io/lfs for more information.
remote: error: File uploads.zip is 200.00 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
...
因为提交历史中有大文件,即错误中信息中的uploads.zip
,需要修改提交历史。
当前stable
分支
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch uploads.zip" --prune-empty --tag-name-filter cat -- stable
结果如下:
Rewrite 916d779538dfeec7b974a677ee3c1a9f74d8dcd2 (38/492)rm 'uploads.zip'
Rewrite 2c4b11542d4942f28460c308c83437665a1c7f40 (492/492)
Ref 'refs/heads/stable' was rewritten
如果要在所有分支重写,将最后的stable
改成all
:
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch uploads.zip" --prune-empty --tag-name-filter cat -- all
强行推送覆盖远程分支
git push origin stable --force
其他协作者需要在本地执行 reset 操作来对齐远程历史。
# 1. 保存当前本地未提交的更改(如果有)
git stash
# 2. 获取远程最新的历史(已经被你重写过的 main)
git fetch origin
# 3. 硬重置本地 stable 到远程 stable
git checkout stable
git reset --hard origin/stable
# 4. 恢复 stash 的更改(如果有)
git stash pop