Search code examples
gitsvnversion-controlgit-svn

Git: missing subdirectories after clone


We are in the process of switching to git for our Version Control system. I used 'git svn' to clone my current svn repository "bigproject" to a git repository - I also setup a cron to sync svn commits to this git repo.

"bigproject" has no defined externals or svn:ignore properties "bigproject" has many directories and sub-directories (upto 7 levels deep) like so.

src/apps/fld1/fld2/fld3/fld4/fld5    

When I inspect the migrated git repo, it seems to have all the folders as expected.

Before actual migration, I setup a staging server and pushed this "bigproject" repo there, and I was trying to switch my build scripts to use git instead of svn.

This is how I hosted the repo on my "git staging" server:

git clone --bare bigproject/ bigproject.git
cp -R bigproject.git /opt/git/
cd /opt/git/bigproject.git
git init --bare --shared

On the build server, after I do a git clone and inspect, I found that some of the subdirectories were missing - esp after 3 levels deep

git@mygitserver:bigproject.git

after the clone I only have

src/apps/fld1

I tried to re-export the bare repo many times to eliminate any human errors but I can't seem to figure out.

Have any of you seen this before?


Solution

  • I can see two possible reasons

    1) you are under Windows and have reached the 255 characters max in terms of PATH length

    2) src/apps/fld1/ contains some files whereas fld2 and all its subdirectories do not contain any file. You cannot add an empty directory in Git, a directory being considered as empty if it does not contain any file. If a directory contain a subdirectory that does not contain any file, you still cannot add it to git. You can check Git FAQ - how to add an empty diectory. Below is an excerpt

    Can I add empty directories?

    Currently the design of the Git index (staging area) only permits files to be listed, and nobody competent enough to make the change to allow empty directories has cared enough about this situation to remedy it.

    Directories are added automatically when adding files inside them. That is, directories never have to be added to the repository, and are not tracked on their own.

    You can say "git add " and it will add the files in there.

    If you really need a directory to exist in checkouts you should create a file in it. .gitignore works well for this purpose (there is also a tool MarkEmptyDirs using the .NET framework which allows you to automate this task); you can leave it empty or fill in the names of files you do not expect to show up in the directory.