git - Tree filter: how to remove all but one directory? -


here's i've tried, result bizarre / unexpected:

git filter-branch -f --tree-filter \ 'for f in $(ls); if [ "$f" != "deploy" ]; \ rm -rf "./$f"; fi done; mv "./deploy/philips/*" .; \ rm -rf "./deploy"' --prune-empty head 

formatted readability. in reality single line.

what happens mv fails because there files left, previous loop didn't remove. action completes "successfully" processing commits, effect remains in root directory isn't filtered / small percent of it.

so, have 2 questions:

  • isn't there easier way purge single directory particular branch?

  • if filter-branch way go, can maybe stack multiple filters? seems executes filter in random order. true?

ps. if can simplify while sacrificing commit history - acceptable solution.

also tried this:

$ git banch   master   preliminary * release-0.6.3  $ git checkout release-0.6.3 master/deploy/philips 

also tried variations master:/deploy/philips, master:deploy/philips, /deploy/philips, deploy/philips , master -- deploy/philips - i'm still no closer goal. :(

edit:

please never mind question. i'm idiot! deploy directory ignored / nonexistent in master! why couldn't check out.

this easy using git subtree. run (for every branch):

git branch newmaster `git subtree split -p deploy/philips` 

now should have new branch newmaster contains history want. check that, delete old master, rename , done.


if don’t have git subtree in git, can read docu here: https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt , install it, download file , put in git-core folder (in cygwin that’s …\cygwin\lib\git-core):

https://raw.github.com/git/git/master/contrib/subtree/git-subtree.sh


Comments