I've seen several articles and questions about how to remove a single file from all git history. Example: How to remove/delete a large file from commit history in Git repository?
What I'd like to do is remove all files that are not currently present at the head of the master branch.
My use case is that I'm splitting off a smaller repository (call it small) from a monolithic repository (call it monolith). I want to preserve the git history when creating small, but only the relevant git history.
First, I created a new repository small on GitHub. Then, on my laptop, I added it as a remote named origin-small to my local monolith repository, and pushed the current state of the master branch of monolith to origin-small.
I then removed the remote origin-small from monolith, changed directories, and cloned small from GitHub. Voilà, I had a copy of my original repository, monolith, with its full history.
But, there are loads of files in the history of small that are no longer relevant, and they are bloating the repo.
What I'd like to do is:
- Delete all of the unnecessary files from
small. - Run a command to clear the whole git history of the files that I just deleted.
Is there a way to do this with a single command? Or do I need to run git filter-branch once for every file/directory that I want to remove?