user797257
user797257

Reputation:

Tree filter: how to remove all but one directory?

Here's what I've tried, but the result is bizarre / unexpected:

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

formatted for readability. In reality this is a single line.

What happens is that mv fails because there are some files left, which the previous loop didn't remove. The action completes "successfully" processing all commits, but the effect is that what then remains in the root directory isn't filtered / only some small percent of it.

So, I have two questions:

PS. If I can simplify it while sacrificing the commit history - this is an acceptable solution.

Also tried something like this:

$ git banch
  master
  preliminary
* release-0.6.3

$ git checkout release-0.6.3 master/deploy/philips

Also tried variations like master:/deploy/philips, master:deploy/philips, /deploy/philips, deploy/philips and master -- deploy/philips - I'm still no closer to the goal. :(

EDIT:

Please never mind this question. I'm an idiot! The deploy directory was ignored / nonexistent in master! this why I couldn't check it out.

Upvotes: 1

Views: 951

Answers (1)

Chronial
Chronial

Reputation: 70763

This is actually really easy using git subtree. Just run this (for every branch):

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

Now you should have a new branch newmaster that contains the history you want. Check that, delete the old master, rename and you are done.


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

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

Upvotes: 3

Related Questions