6

I convert a CVS repository to a Git repository with the following command:

$ git cvsimport -vaikd :pserver:thillaiselvan@192.168.1.11:2401/ -C IVR-GUI GIT

However, Git ignores the empty directories in the CVS repository. But I want the repository to be cloned including those empty repositories. How can I make Git to do that?

David Cain
  • 16,484
  • 14
  • 65
  • 75
thillaiselvan
  • 637
  • 6
  • 18

1 Answers1

5

Git cannot track empty directories, so they're not brought over in the CVS-Git conversion. From the Git FAQ: "Directories are added automatically when adding files inside them." Your directories don't appear because Git isn't tracking anything within them.

How to track empty repositories in Git

One workaround to track empty directories is to place an empty file, like .gitkeep in each empty directory (.gitkeep is used by convention, but you can name this file anything you want). Track the files, then you'll be able to clone empty directories. There are a few other ways to add empty directories to a Git repository.

Manually copy empty files from a pre-existing CVS repository

The following command will copy all empty directories in your cvs repo to your Git repository (substitute the dummy directory paths)

$ find ~/cvs_repo -type d -empty -exec cp -r {} ~/git_repo/ \;

You can then add these empty directories to your project with your workaround of choice, and follow up with something like $git commit -m "Add empty directories to repository".

Automating the procedure with cvsimport?

Now, I would assume that cvsimport would compensate for this difference in VCS (CVS lets you track empty directories, Git does not). I don't know anything about the tool, but maybe there's an option you can pass to have it automatically handle adding empty directories.

Community
  • 1
  • 1
David Cain
  • 16,484
  • 14
  • 65
  • 75
  • Actually I have converted the cvs repositories to git. Now cloning them from git, I unable to get those empty directories :( – thillaiselvan Aug 10 '12 at 04:00
  • 1
    I usually add an empty .gitignore file. – Milan Babuškov Aug 10 '12 at 04:05
  • 1
    David and Milan are both correct, but the convention that I've seen (and hence used) most often is to create an empty .gitkeep file in the directory that you want to retain. .gitkeep doesn't mean anything **special** to Git, but it's a file (so it will keep the directory around), and its purpose is perfectly obvious based on its name. – Bob Gilmore Aug 10 '12 at 04:09
  • @thillaiselvan, if I understand correctly, your problem is that you can't get empty directories that CVS once tracked in your current Git repository? I added a section that should help. Please let me know if I've misunderstood. – David Cain Aug 10 '12 at 04:15
  • @David, I have converted the cvs repositories to git like, git cvsimport -v -a -i -k -d :pserver:thillaiselvan@192.168.1.11:2401/ -C IVR-GUI GIT. Now the IVR-GUI repository became a git repository in a server. In my working machine I tried to clone the IVR-GUI repository. It cloned. But it didn't contain the empty directories. public/images got ignored.... – thillaiselvan Aug 10 '12 at 04:17
  • 1
    @thillaiselvan. Okay! You should include that in your question next time. So, what you'll want to do is ssh into your server, find all empty directories with the `find` command I gave above, and manually copy those to your new Git repository (then add those directories with your chosen hack). During the cvs-Git conversion, my guess is that those empty directories were lost. You need to manually compensate for this difference between Git and cvs. – David Cain Aug 10 '12 at 04:23