2

I had some large files that were accidentally tracked in git. I didn't realize until many commits later. I moved those files into git LFS, but now I would like to delete them out of my normal git database as their deltas are taking up a huge amount of space.

Nick Chapman
  • 4,402
  • 1
  • 27
  • 41

1 Answers1

2

Be aware that all solutions are history rewrites, which will require a level of coordination with everyone who has a clone of the repo to avoid your work being undone.

Three tools that can handle this, each with pros and cons:

The most specialized to your purpose would be lfs migrate. https://github.com/bozaro/git-lfs-migrate

Another option would be BFG. In my experience it does some things a little better, and others not as well, compared with lfs-migrate. It also has the option to just rip the big files out without substituting in pointer files, if you don't care about breaking the history. https://rtyley.github.io/bfg-repo-cleaner/

Or if you want to stick to git built-in commands, there's git filter-branch (but it will be slower and harder). You could set up an index-filter to git rm --cached --ignore-unmatch the affected paths (if they don't move around). This might be slow and will break the affected commits. You could instead use a tree-filter that replaces the affected paths with the appropriate pointer files and inserts a suitable .gitattributes file. This is even slower (and potentially harder to get right.)

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52