How can I remove all files larger than X MB from all my unpushed Git commits?
Asked
Active
Viewed 1,561 times
2
-
Do an interactive rebase (and edit all newer commits), iterate through all files, test if the are bigger than X MB and remove them. – dan1st Nov 17 '19 at 08:21
-
Possible duplicate of [How to remove/delete a large file from commit history in Git repository?](https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-git-repository) – phd Nov 17 '19 at 12:04
-
https://stackoverflow.com/search?q=%5Bgit%5D+remove+large+files+history – phd Nov 17 '19 at 12:04
-
Sorry for this poor experience. I am always grateful for moderator, but your question, specifically on unpushed commit, was just fine. – VonC Nov 17 '19 at 16:54
-
There are at this point 4 "reopen"s; one more should do it. Note that the existing "remove large files" questions-and-answers are generally the right ones, the only constraint you've added is "unpushed commits". For one particular branch `foo`, the range-restriction `origin/foo..foo` should do the trick with `--filter-branch` or `filter-repo`. – torek Nov 17 '19 at 18:34
-
@VonC and unsurprisingly my previous comment got removed... – Franck Dernoncourt Nov 18 '19 at 00:06
1 Answers
6
To purge the history of the repository, you might consider the new tool git filter-repo
which replaces BFG and git filter-branch
.
git filter-repo --strip-blobs-bigger-than 10M --refs master~3..master
Replace 3 by the number of unpushed commits you have (FYI: view unpushed Git commits).
Or:
git filter-repo --strip-blobs-bigger-than 10M --refs origin/master..master
Note if you get the error message Error: need a version of git whose diff-tree command has the --combined-all-paths option
when running the above-mentioned commands, it means you have to update git
.

Franck Dernoncourt
- 77,520
- 72
- 342
- 501

VonC
- 1,262,500
- 529
- 4,410
- 5,250