tags:

views:

49

answers:

2

I have an existing git repository with a reasonable amount of history that I don't want to lose. The problem is that I would like to add directories that are above the current git root dir. I know that the following wont work:

git add ../[dir]/[filename] 

It would seem that I need to do an export/import to get this working. Can anybody help me save my history? Am I on the right track, or is there a much simpler way to do this?

A: 

you can symlink that dir into your git dir:

ln -s ../[dir] externaldir
git add externaldir
Antony Hatchkins
Thanks for the suggestion. That is one way to fix the problem. If however I forget to delete the symlink on checkout then I could expose files to untrusted sources that I don't want exposed. I am looking for a solution that doesn't alter the existing file system layout.
neomorphic
If your layout in another working dir differs from the first one, you could consider hard link to directory so that your files are not exposed.
Antony Hatchkins
On one hand you want your files in `../dir` to be put under version control, on the other - not to be exposed to untrusted sources. Can you clarify?
Antony Hatchkins
I want to be able to checkout the repo onto a machine and point my webserver to the directory below the top level, so that there is no chance that the files in the top level are exposed to the outside world if the webserver configuration gets messed up.
neomorphic
A: 

So here is how I fixed this for myself. Given the original file layout

top-+
    |
    |-foo-+
    |     |-page1
    |     |-.git
    |
    |-bar-+
          |-page2

I wanted to add the bar directory to my repository and have the .git file directly inside the 'top' dir.

  • create a new foo directory inside the existing repositry

  • move all the versioned files into the new foo dir using git mv

  • move the bar directory into the original foo directory and the file system should now look like this:

 top-+
     |
     |-foo-+
           |-.git
           |-foo-+
           |     |-page1
           |
           |-bar-+
                 |-page2

  • move the original foo directory up one level
 /-+
   |-top/
   |-foo-+
         |-.git
         |-foo-+
         |     |-page1
         |
         |-bar-+
               |-page2

  • delete top and rename foo to top
  • commit the changes

The version history is maintained and you have a commit message to show how the directory structure was changed.

neomorphic