This is a short note regarding the use of `git filter-branch` when you want to split a git repository and preserve the history.
I had some issues in finding the correct parameters. In case this also can help others, you can find the command here.
In case you are not yet familiar with the possibilities of `git filter-branch`, I suggest you look into the Git book: Rewriting history, which has a good introduction to the command.
Now, to start you should clone the repository you want to change (since you will completely rewrite history in the new repos).
In short, without further explanation:
git clone $ORIG $DEST && \
cd $DEST && \
git filter-branch –prune-empty –tag-name-filter cat –subdirectory-filter $DIR — –all
A few notes:
will remove all commits that has no relation to the folder you extract
will also rewrite any tags you put on the commits that are rewritten
takes a foldername as parameter, but I needed to add— –all
to make it work