Git Push因历史提交含超大Zip触发文件大小限制报错,需保留有效修改
Got it, let's work through this problem step by step. The root of the issue is that Git pushes your entire commit history when you push your latest changes—so that problematic commit (f0ce53a) with the oversized zip is getting dragged along every time. We need to rewrite that commit to remove the zip file while keeping its valid changes, then update your remote repo safely.
Solution 1: Interactive Rebase (Best for Recent Commits)
This method lets you directly edit the problematic commit without rewriting too much of your history:
Start an interactive rebase targeting the commit right before f0ce53a:
git rebase -i f0ce53a^This will open a text editor listing all commits from f0ce53a onward.
In the editor, change the word
picknext to commitf0ce53atoedit, then save and close the editor. Git will now pause at the state of that commit.Remove the oversized zip file from the commit:
# Use --cached if the file is already in .gitignore, omit it otherwise git rm --cached path/to/your/large/file.zipAmend the commit to save the change (keeping the original commit message):
git commit --amend --no-editResume the rebase process:
git rebase --continueIf you hit any merge conflicts, resolve them, stage the resolved files with
git add, then rungit rebase --continueagain.Push your rewritten history to the remote. Since we modified existing commits, we need a force push—but use the safer
--force-with-leaseoption to avoid overwriting others' work:git push --force-with-lease origin your-branch-name
Solution 2: git filter-repo (Best for Bulk History Edits)
If you have multiple commits that might include the zip file, or if the rebase feels too tedious, use git filter-repo (the modern replacement for the outdated git filter-branch):
First, back up your local repo—this rewrites history, so having a copy is critical:
cp -r your-repository-folder your-repository-folder-backupRun the filter command to remove the zip file from all commits:
git filter-repo --path path/to/your/large/file.zip --invert-pathsPush the rewritten history to the remote with a safe force push:
git push --force-with-lease origin your-branch-name
Important Notes
- If you're collaborating with a team, warn your teammates that you've rewritten the branch history. They'll need to rebase their local copies or clone the repo fresh to avoid conflicts.
- Add the zip file to your
.gitignoreto prevent accidentally committing it again:echo "path/to/your/large/file.zip" >> .gitignore git add .gitignore git commit -m "Add zip file to .gitignore" git push origin your-branch-name
内容的提问来源于stack exchange,提问作者Eironeia

