How to clone CVS repository with empty directories
Asked Answered
D

1

6

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

$ git cvsimport -vaikd :pserver:[email protected]: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?

Designation answered 10/8, 2012 at 3:47 Comment(0)
T
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.

Trainman answered 10/8, 2012 at 3:51 Comment(6)
Actually I have converted the cvs repositories to git. Now cloning them from git, I unable to get those empty directories :(Designation
I usually add an empty .gitignore file.Unwitnessed
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.Polycrates
@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.Trainman
@David, I have converted the cvs repositories to git like, git cvsimport -v -a -i -k -d :pserver:[email protected]: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....Designation
@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.Trainman

© 2022 - 2024 — McMap. All rights reserved.