GIT-CLONE-SUBSET(1) | General Commands Manual | GIT-CLONE-SUBSET(1) |
git-clone-subset - Clones a subset of a git repository
git-clone-subset [options] repository destination-dir pattern
Clones a repository into a destination-dir and prune
from history all files except the ones matching pattern by running on
the clone:
git filter-branch --prune-empty --tree-filter 'git rm ...' -- --all
This effectively creates a clone with a subset of files (and history) of the
original repository. The original repository is not modified.
Useful for creating a new repository out of a set of files from
another repository, migrating (only) their associated history. Very similar
to:
git filter-branch --subdirectory-filter
But git-clone-subset works on a path pattern instead of just a single
directory.
Pattern Examples:
"*.png"
"*.png|*icon*"
"*.h|src/|lib"
Renames are NOT followed. As a workaround, list the rename history with 'git log --follow --name-status --format='%H' -- file | grep "^[RAD]"' and include all multiple names of a file in the pattern, as in "current_name|old_name|initial_name". As a side effect, if a different file has taken place of an old name, it will be preserved too, and there is no way around this using this tool.
There is no (easy) way to keep some files in a dir: using 'dir/foo*' as pattern will not work. So keep the whole dir and remove files afterwards, using git filter-branch and a (quite complex) combination of cloning, remote add, rebase, etc.
Pattern matching is quite limited, and many of bash's escaping and quoting does not work properly when pattern is expanded inside !().
https://github.com/MestreLion/git-tools
Rodrigo Silva (MestreLion) linux@rodrigosilva.com
2021-02-11 |