4

How do you remove mistakenly committed large files from commit history? Git won't push any more commits to remote until I remove problematic files. I've since attempted to remove them but they exist in previous commits.

Note: I do not need the large files anymore in project.

On git push origin my-branch I get:

remote: warning: File public/images/reserve_assets/myfile.tif is 63.60 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 0c08ce8916353c82c7328a241a40c8ca
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File public/images/reserve_assets/myotherfile.tif is 107.34 MB; this exceeds GitHub's file size limit of 100.00 MB

Then

! [remote rejected] my-branch -> my-branch (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:RepoOwner/myrepo.git'

I've tried git filter-branch --tree-filter 'rm -f myfile.tif' HEAD which performs the rewrites across the commit history. It outputs

Rewrite 1cd9b031d047d4270ff8b488b3b5e8db2905c687 (87/93) (12 seconds passed, remaining 0 predicted)

But then says WARNING: Ref 'refs/heads/my-branch' is unchanged. It seems like it's rewriting and removing from the history but I still cannot push.

user3871
  • 12,432
  • 33
  • 128
  • 268
  • 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 Apr 09 '19 at 08:29
  • https://stackoverflow.com/search?q=%5Bgit%5D+remove+large+file+history – phd Apr 09 '19 at 08:29

1 Answers1

2

I had other files which were large too. You cannot remove a single file at a time via git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD as each time it creates a single backup.

Removing the entire problematic folder via git filter-branch -f --tree-filter 'rm -rf path/to/folder' HEAD with additional -f to force former backup rewrite does the trick (assuming you've tried previously with removing a single file)

user3871
  • 12,432
  • 33
  • 128
  • 268
  • 2
    Actually, you *can* remove one file at a time. You just *shouldn't* because filter-branch is so slow. It also goes much faster if you use the `--index-filter`, for which you must use `git rm --cached --ignore-unmatch` instead of plain `rm -f` (the rest of the rules are pretty similar). – torek Apr 09 '19 at 05:47