2

I'm using GitHub and have run into a bit of a problem with large files.

I updated a 3rd party library, and it added a file of size 119.41 MB. So now in Sourcetree when I try to push to GitHub I get the following warning:

remote: error: File Pods/Realm/core/realm-monorepo.xcframework/watchos-arm64_i386_x86_64-simulator/librealm-monorepo.a is 119.41 MB; this exceeds GitHub's file size limit of 100.00 MB

Unfortunately I've done a bunch of work after that commit, and it needs to pushed to the repo.

Is there a way to go through every historic commit of the of project and delete all files with the name librealm-monorepo.a?

Apologies if this is an obvious question, but my Git skills are quite weak, and I'm rather nervous about accidentally screwing up the whole project. So all advice would be greatly appreciated :)

Jon Cox
  • 10,622
  • 22
  • 78
  • 123

1 Answers1

4

You can use the tree-filter with filter-branch which will delete the file entirely from history,

git filter-branch --tree-filter 'rm -rf librealm-monorepo.a' HEAD

EDIT 1: START

For rewriting history, Git now recommends using an alternative tool called git filter-repo instead of the filter-branch.

From the Git documentation :

Please use an alternative history filtering tool such as git filter-repo.

The above filter-branch command could be rewritten for the suggested filter-repo as follows:

git filter-repo --invert-paths --path librealm-monorepo.a

EDIT 1: END

Asif Kamran Malick
  • 2,409
  • 3
  • 25
  • 47
  • maybe worth calling out that if it's only a few commits `git rebase -I origin/` and removing the offending commits is ~easier and will result in the same thing. – AD7six Feb 28 '21 at 16:43