0

Possible Duplicate:
Detach subdirectory into separate Git repository

I guess what I'm asking is completely impossible... but it's worth to ask :)

I've got a repository where I saved both code and binary files (like PSDs). The folders structure it's like this (hugely simplified):

  • GIT-PROJECT
    • DESIGNS
    • CODE

What I'd like to do now is splitting DESIGNS and CODE... I will then move DESIGNS to Dropbox and instead carry-on saving CODE on github.

So... my question is can I start a new git repository with CODE as root and keep the commit history for that folder?

NOTE: one of the reasons why I wanna get rid of the DESIGNS folder is that I need to save space :) DESIGNS got huge during the time... and I would prefer not to upgrade my Github paid plan because of that.

Thanks!

Community
  • 1
  • 1
Andrea
  • 638
  • 9
  • 20
  • Thanks! I searched before... but with no luck. This sure looks like what I'm after... as Charles suggested. I'll have a look, Thanks! – Andrea Oct 15 '11 at 13:38

2 Answers2

1

git filter-branch does the trick of keeping the history and dropping everything else.

$ git filter-branch --subdirectory-filter CODE

Beware this is destructive. Later you might want to do:

$ git reflog expire --expire=now
$ git gc --prune=now

You will see a considerable reduction of the repository size, only having the history of CODE and removing all those unreachable objects.

gpoo
  • 8,408
  • 3
  • 38
  • 53
  • `--aggressive` is probably not a good idea, and `gc` includes `prune`. You probably meant `git reflog expire --expire=now` followed by `git gc --prune=now`. – Cascabel Oct 15 '11 at 22:49
  • reflog expire it is better. --aggressive still can be necessary, but it might depend on a specific case. I fixed to make it less dangerous. Thanks! – gpoo Oct 16 '11 at 05:44
0

Why not just commit a change that removes the DESIGNS and moves the CODE up to the top level? This way history will be completely and accurately preserved.

E.g. (from GIT-PROJECT)

git rm -r DESIGNS # assumes you've saved DESIGNS somewhere
git mv 'CODE/*' .

git commit -m "Removed DESIGNS, moved code to the top level"

If you really want to expunge DESIGNS from the history of the repository and pretend that the code was always at the top level you can use git filter-branch with the --tree-filter or --subdirectory-filter to rewrite history, although this is a more involved change.

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
  • Sorry... I forgot to mention that I'm using github and I'd like to remove DESIGNS to save space. Just removing the folder and then commit the change, wouldn't make any difference I guess. – Andrea Oct 15 '11 at 13:35