Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import an existing CVS module into a subdirectory of an existing git repository

Tags:

git

cvs

I'm resurrecting a rather old code project, from when I was using CVS regularly, as a component in a new project that I've already been working on using git. I still have access to the CVS archive the old project's module is in, so I was just going to use git-cvsimport to get the commit history and go from there. However, this is just creating a new git repository inside of the current one. It's entirely possible I need to do this as a multistep process where I go CVS -> fresh git repository and then use something else to get it into the existing git repository.

Running this in newproj/newsubdir ($CVSROOT is already correctly set in my shell configuration):

git cvsimport -k -o master -u -s \- -A ~/Documents/cvs-authors.txt oldproj

gets me a brand new repository newproj/newsubdir/.git/ with all of the correct commits (comments, timestamps, history), and with HEAD where I want it.

What I want is for the historical CVS commits to be as if they were always in newproj/newsubdir/oldproj-file1, newproj/newsubdir/oldproj-file2, etc. In my experience, git has the magic to do this kind of thing, but I couldn't find an obvious fit to my situation.

like image 549
UltraNurd Avatar asked Dec 01 '09 23:12

UltraNurd


People also ask

How do I transfer my CVS code to git?

You can use git-cvsimport to import your CVS repository into Git. By default, this will check out every revision, giving you a relatively complete history. Depending on your operating system, you may need to install support for this separately. For example, on an Ubuntu machine you would need the git-cvs package.

How do I import existing git repository?

Import into a new repoSelect Repos, Files. From the repo drop-down, select Import repository. If the source repo is publicly available, just enter the clone URL of the source repository and a name for your new Git repository.

Is the command used to get files from the remote repository directly into working directory?

The git fetch command downloads commits, files, and refs from a remote repository into your local repo. Fetching is what you do when you want to see what everybody else has been working on.


1 Answers

You have three options. All of them start with doing the clean cvsimport, so go ahead and do that.

  1. Reference that repo as a submodule.
  2. Fetch the repo into the existing repo and do a subtree merge to join the histories.
  3. Do something similar to #3, and then regraft the tree as to interleave the commits chronologically throughout history.

Number one means that the outer project relies on the inner, but is probably not desirable for you.

Number two is explained in this subtree merge howto. It might be good enough for you.


But if you like a nice clean linear history, you can do #3 and tangle them up for good. I did something similar in a cleanup project a while back and have a lot of the documentation and tools still there.

The basic idea was to separate all of the changes into a patch history that would reconstruct the changes. By default, this history is in a sort of repository order, but running the script I mentioned in the post will rearrange the patches into a new sequence in chronological order.

The tree hash should let you know you didn't break anything other than the lineage.

Were I to do this again, I'd possibly just emit a grafts file and do a filter-branch.

like image 114
Dustin Avatar answered Nov 11 '22 05:11

Dustin