Git subdirectory filter with existing directory structure

后端 未结 2 1872
北荒
北荒 2021-02-05 15:42

I\'m splitting out a Git repository using the --subdirectory-filter option of filter-branch which is working great except it pulls everything up to the root of the repository.

2条回答
  •  感动是毒
    2021-02-05 16:23

    I've only given this cursory testing myself, but I think you can use git filter-branch with --tree-filter to rewrite the branch, but removing all files apart from those in the subdirectory ABC/DEF, with something like the following:

    git filter-branch --tree-filter \
        'find . -path ./ABC/DEF -prune -o -type f -print0 | xargs -0 rm -f' \
        --prune-empty HEAD
    

    Note that the find command only removes files, not directories, but since git doesn't store empty directories, this should still produce the result you want.

提交回复
热议问题