Reputation:
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:
Isn't there an easier way to purge all but a single directory from a particular branch?
If filter-branch
is the way to go, can I maybe stack multiple filters? It seems like it executes the filter in random order. Is that true?
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
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