1

How can I remove all files larger than X MB from all my unpushed Git commits?

Franck Dernoncourt
  • 62,576
  • 61
  • 286
  • 446
  • 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 Answers1

5

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
  • 62,576
  • 61
  • 286
  • 446
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283