63

I intend to switch over from CVS to Git. In the case of SVN, there seems to be cvs2svn. Is there a similar tool to easily migrate from CVS to Git?

Shiva
  • 20,575
  • 14
  • 82
  • 112
freddiefujiwara
  • 57,041
  • 28
  • 76
  • 106

12 Answers12

32

The only tool that has incremental import seems to be git-cvsimport. If you want to convert (migrate) from CVS to Git, the best solution for now seems to be mentioned above cvs2git mode of cvs2svn.

See also Interfaces Frontends And Tools page on Git wiki, section about interaction with other revision control systems.

8None1
  • 405
  • 4
  • 9
Jakub Narębski
  • 309,089
  • 65
  • 217
  • 230
18

cvs2git

In addition to provided answers, here's a guide on how to convert cvs to git using cvs2git tool. Here, modulename is a name of CVS directory you want to import.

Prerequisites

cvs2svn package (which includes cvs2git command) should be already installed.

Update: steps 1 and 2 are not fully correct - before attempting, read the comment below by mhagger, the maintainer of cvs2git

  1. checkout modulename

    cvs -d URL co -P modulename
    
  2. create an empty CVSROOT needed by cvs2git

    mkdir modulename/CVSROOT
    
  3. download an example of cvs2git.options at http://cvs2svn.tigris.org/svn/cvs2svn/trunk/cvs2git-example.options (user "guest" with no password)

  4. edit cvs2git.options file. Replace r'test-data/main-cvsrepos' with 'modulename'. Edit authors transforms.

    # edit this
    run_options.set_project(  r'modulename',
    
    # and this
    author_transforms={
        'jrandom' : ('J. Random', 'jrandom@example.com'),
        'mhagger' : 'Michael Haggerty <mhagger@alum.mit.edu>',
    
  5. run cvs2git to create git temp files

    cvs2git  --options=cvs2git.options --fallback-encoding utf-8
    
  6. create git repository

    mkdir gitrepo && cd gitrepo && git init .
    
  7. import from git temp files created by cvs2git

    cat ../cvs2git-tmp/git-{blob,dump}.dat | git fast-import
    
  8. checkout working copy

    git reset --hard
    
Vanuan
  • 31,770
  • 10
  • 98
  • 102
  • The example options file link asks for a user/password. Its in the cvs2git documentation under usage. http://cvs2svn.tigris.org/cvs2git.html – txyoji Jun 17 '13 at 18:33
  • You can use "guest" with no password. – Vanuan Jun 17 '13 at 19:47
  • cvs2git seems to be very sensitive about using the correct .options file to the version of the script you are using so use the one that comes with the version you are trying. – Sedrik May 06 '14 at 12:29
  • 20
    This answer is wrong! You can't do a `cvs2git` conversion from a checked out working copy of a repository! You have to run it against the repository itself; i.e., the directory that *already* contains a `CVSROOT` subdirectory and lots of `filename,v` files. If you are using a central CVS server, the repository that you need is located on the server. – mhagger Aug 28 '14 at 06:47
  • @mhagger I don't understand what you are talking about. I ran it against checked out csv repo just fine. – Vanuan Aug 28 '14 at 14:17
  • 14
    @Vanuan: I'm the maintainer of cvs2svn/cvs2git and I say that it is *not possible*. cvs2git *needs* filesystem access to the full history of the repository; i.e., the `filename,v` files that contain all of the file revisions. A checked-out working copy only contains a single version of the project. cvs2svn does not know how to retrieve older revisions from the server. Ergo, it is not possible. You must have confused yourself by running different commands than you describe above. – mhagger Sep 01 '14 at 11:46
  • @mhagger I assure you that I successfully converted cvs repository http://sourceforge.net/p/sweethome3d/code/ to git https://github.com/Vanuan/sweethome3d without having administrative access to the sourceforge server. However, i'm not experiences with CVS. It may be that sourceforge provides anonymous administrative access or as you said I used a different command. Can you suggest which command did I run? – Vanuan Sep 01 '14 at 16:37
  • 4
    @Vanuan: sourceforge allows you to [download your CVS repository using rsync](http://sourceforge.net/p/forge/documentation/CVS/#backups). This is different than checking it out; it gives you the whole repository including its history. Once you have that, you can use `cvs2git` to convert to Git. – mhagger Sep 09 '14 at 15:14
  • 1
    Indeed mhagger is right, but the whole process described by Vanuan works very well (both on Windows and Linux) if you import the SourceForge CVS repo using `rsync -av rsync://PROJECT.cvs.sourceforge.net/cvsroot/PROJECT/\* cvs` – gaborous Mar 09 '15 at 20:53
  • 1
    @mhagger `TypeError: __init__() got multiple values for keyword argument 'blob_filename'` – Alex Aug 14 '15 at 10:09
  • @Alex: Instead of using the trunk version of `cvs2git-example.options` above, use the one that matches your version (from eg. `/usr/share/doc/cvs2svn/cvs2git-example.options`) and it should work fine. – Jani Dec 28 '15 at 10:53
  • @mhagger: Can you explain, or link to an explanation, of how to download the repository with history, when it's on a "pserver"? – einpoklum Jun 23 '20 at 21:14
  • tigris.org site is currently down. Github has the project now: https://github.com/mhagger/cvs2svn – Matthew B. Nov 05 '20 at 20:13
13

cvs2svn has a cvs2git mode.

bdonlan
  • 224,562
  • 31
  • 268
  • 324
10

If anyone still has the misfortune of using CVS, you could try "crap" : https://github.com/rcls/crap It's fast (as far as accessing CVS can be fast), supports the messes that you find in cvs repos, and incremental.

user2603340
  • 101
  • 1
  • 2
  • 4
    "crap" is the life saver. It's the only thing that has worked for me so far! – York Sep 26 '15 at 04:01
  • Worked for me too - except that it has an [issue with passwords](https://github.com/rcls/crap/issues/22) - I had to patch the code to use my own password as the fallback... :-( – einpoklum Jun 23 '20 at 21:37
  • ... and then an issue with misnamed tags. So, I have a copy of the repo with some patches, [here](https://github.com/eyalroz/crap), which you might find useful. – einpoklum Jul 01 '20 at 20:15
7

An alternative might be to use git cvsimport *

rtn
  • 127,556
  • 20
  • 111
  • 121
  • 13
    git cvsimport is broken and will silently give incorrect results on all but the most trivial CVS repositories. For example, see the "ISSUES" section in its documentation (http://www.kernel.org/pub/software/scm/git/docs/git-cvsimport.html), or run its unit tests. – mhagger Aug 27 '10 at 08:04
6

I've not tried this myself, but friends have reported good success converting first from CVS to SVN, and then from SVN to Git. It seems that the tools to do those respective transitions have been more thoroughly shaken out than a direct CVS to Git transition.

Dave W. Smith
  • 24,318
  • 4
  • 40
  • 46
2

I've tried cvs2git, git-cvsimport and parsecvs.

cvs2git sometimes (as far as I remember) creates bogus branches for tags.

git-cvsimport does not support multiple tags for a changeset. It is possible however to grab some additional changes for cvsps to support it and change the original git-cvsimport to something which uses updated cvsps (I've tried it and it seems to work). On the advantage side it supports incremental updates and has some logic to properly import merges (but it REQUIRES appropriate format for commit message).

parsecvs so far gave me the best results. Unfortunately the code available on the web does not compile cleanly with the latest git. The change while not trivial is doable.

EDIT: It looks like ESR took over both cvsps and parsecvs so there is some hope for CVS->GIT migration. BUT he already mentioned on some mailing list that he may declare some of the tools he took over recently officially dead.

Tomek
  • 4,554
  • 1
  • 19
  • 19
  • Yes, I deep-sixed cvsps in favor of parsecvs after comparing them rigorously. Later I gave cvsparse the ability to ship a fast-import stream and it became cvs-fast-export. – ESR Feb 14 '20 at 00:15
2

I read the answer by Vanuan and mhagger's comments to it. Unfortunately mhagger didn't post how to do it with cvs2git. It is all very well written up here: http://www.mcs.anl.gov/~jacob/cvs2svn/cvs2git.html

I used cvs2git instead of git-cvsimport because the documentation of git-cvsimport suggests to use it instead to avoid the problems of git-cvsimport: https://www.kernel.org/pub/software/scm/git/docs/git-cvsimport.html#issues

It follows essence of it that worked for me to create a git repository from a sourceforge CVS repository on Debian Sid:

$ apt-get install cvs2svn cvs
$ mkdir project.cvs
$ rsync -av rsync://${PROJECT}.cvs.sourceforge.net/cvsroot/${PROJECT}/ project.cvs
$ cvs2git --blobfile=git-blob.dat --dumpfile=git-dump.dat --username=cvs2git project.cvs
$ mkdir project.git
$ cd project.git
$ git init
$ cat ../git-blob.dat ../git-dump.dat | git fast-import

The rsync step is needed because cvs2git needs access to the whole history. A simple checkout is not enough.

josch
  • 6,716
  • 3
  • 41
  • 49
2

I'm the maintainer of cvs-fast-export. I used to maintain cvsps and parse2cvs and have closely evaluated cvs-fastimport and cvs2git.

CVS to git conversion is a hard, nasty problem with rebarbative edge cases. All the existing conversion tools have known limitations, some quite serious.

I recommend trying cvs-fast-export first. It produces better, faster conversions than anything else, except in rare cases where it fails cleanly and bails out. If you get the rare but dreaded "branch cycle error", try cvs2git.

Do not trust cvs-fastimport, it is quite buggy and often screws up branch joins.

For more, see http://www.catb.org/esr/cvs-fast-export/

ESR
  • 574
  • 1
  • 5
  • 10
1

You can use git cvsimport. It requires cvsps to be installed, but you need to install 2.x, as 3.x is not incompatible anymore.

Then import CVS repository on empty git. Sample usage:

git cvsimport -C RepoName -r cvs -o master -k -v -d:pserver:anonymous@reponame.cvs.sourceforge.net:/cvsroot/path ModuleName

On OSX you install cvsps-2.1 in the following way (having brew):

brew tap homebrew/versions
brew install cvsps2
brew link  cvsps2

You can also use cvs2git tool which can convert a CVS repository to git. However you need to have access to a CVSROOT directory.

Check cvs2git documentation for installation steps.

Example usage:

cvs2git --blobfile=git-blob.dat --dumpfile=git-dump.dat --username=cvs2git /path/to/cvs/repo

This would create two output files in git fast-import format. The names of these files are specified by your options file or command-line arguments. In the example, these files are named cvs2git-tmp/git-blob.dat and cvs2git-tmp/git-dump.dat.

These files can be imported into empty git repository by:

cat git-blob.dat git-dump.dat | git fast-import

Then delete the TAG.FIXUP branch and run gitk --all to view the results of the conversion.

Check for more, by running: cvs2git --help.

Community
  • 1
  • 1
kenorb
  • 155,785
  • 88
  • 678
  • 743
  • 1
    Thanks for the tip about cvsps version - was getting stuck on that. – Mark Jul 01 '15 at 00:54
  • The [cvsimport](https://www.kernel.org/pub/software/scm/git/docs/git-cvsimport.html) man page is full of warnings, deprecations, and more warnings. It recommends the use of cvs2git instead. – Edward Falk Apr 14 '16 at 01:45
1

You can add fromcvs to the list. It converts well and is extremely fast and also incremental. It does not do sticky tags, only branches, however.

robinr
  • 4,376
  • 2
  • 20
  • 18
0

I found cvs-fast-export did an excellent job. I had to download and compile it myself, but didn't have any significant issues doing so.

Edward Falk
  • 9,991
  • 11
  • 77
  • 112