extract multiple directories using git-filter-branch

后端 未结 4 1661
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 07:55

I have a big repository which currently contains multiple projects in top level subfolders, say /a, /b, /c, and /d.

4条回答
  •  时光取名叫无心
    2020-12-02 08:32

    Use

    git filter-branch -f --prune-empty --tree-filter 'bash preserve-only.sh a b' -- --all
    

    where preserve-only.sh is:

    IFS=':'
    GLOBIGNORE="$*"
    rm -rf *
    

    This should remove everything but a and b from all commits of all branches, which should be the same as extracting exactly the given directories.

    To complete the actual split you can use a filter like rm -rf a b to get all the changes not extracted in the first run.


    Update: While trying to speed things up using --index-filter I came to an even easier solution:

    git filter-branch -f --prune-empty --index-filter \
      'git rm --cached -r -q -- . ; git reset -q $GIT_COMMIT -- a b' -- --all
    

    This just removes everything and afterwards restores the given directories afterwards.

提交回复
热议问题