开发者

Can an external directory be added to an existing git repository

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]/[fi开发者_如何转开发lename] 

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?


you can symlink that dir into your git dir:

ln -s ../[dir] externaldir
git add externaldir


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜