Search code examples
gitgit-subtreegit-filter-branch

Split file into separate repository, preserving history


I want to do the equivalent of git-subtree split only on a single file rather than a directory. That is, I want to make a new repository having only that one file and all its history.

Passing the filename to the --prefix argument does not work

git subtree split --prefix=file_name -b split

I tried a couple variations on git-filter-branch but did not find the correct incantation.


Solution

  • You could use filter-branch with a tree-filter deleting everything except the file you want to keep like

    git filter-branch --tree-filter 'find -type f -not -path ./foo/bar -delete' --prune-empty