How to import and keep updated a CVS repository in Git?
Asked Answered
L

3

40

There is a central repository in CVS, and I would like to use it with Git locally, and then send my changes back to CVS.

What can I accomplish that on a daily basis?

The tasks I would like to accomplish are:

  • importing branches,
  • getting history in GIT-like format, and
  • exporting back my changes/commits to the centralized server

BTW, I have also looked at Best practices for using git with CVS . But It didn't work and I couldn't figure out what I missed or did wrong.

Lariat answered 6/7, 2012 at 12:57 Comment(7)
You should explain why git-cvsimport doesn't work for you. Also for this question git-svn is totally unrelated (or provide a link if there is a tool svn-git which deals with CVS).Pelican
@honk, I believe git-cvsimport is only one way ticket to GitTolley
@AlexeyShytikov, there is still git-cvsexportcommit to get your work into the CVS repo. While not the same awesomeness as git-svn, it is still much more useful than plain CVS.Pelican
@honk you right I've missed that point.Tolley
possible duplicate of Is there a migration tool from CVS to Git?Biagio
I really can't understand why this has to be closed. "opinion-based" ? A how-to of copying a source repository back and forth?Floccose
Here is an effective tool I just used for a long delayed migration: github.com/rcls/crapGrossularite
O
59

What I have done in the past is:

Import the CVS repository

Using:

$ git cvsimport -C target-cvs -r cvs -k -vA authors-file.txt -d $CVSROOT module

Where:

  • target-cvs is the directory to keep my local copy of the repository.
  • cvs is the name to use for referencing the remote repository. So, I will have cvs/master, cvs/HEAD, etc. pointed locally by master.
  • authors-file.txt is the file that contains the matches between CVS account and Name+email, each line contains userid=User Name <useremail@hostname>
  • $CVSROOT is the CVS respository server. If I use an anonymous cloning from some sourceforge repository, then I would use: :pserver:anonymous@project_name.cvs.sourceforge.net:/cvsroot/project_name
  • module is the module inside of the repository I want to clone. If the repository has only one module, then likely will be the same as project_name.

Update the repository

It is possible to repeat the command I wrote previously. In that particular example, it should be run in the parent directory of target-cvs. To make it easier in the future, you might want to configure some variables (you can read more details in the answer of "How to export revision history from mercurial or git to cvs?")

$ git cvsimport

That would be enough to keep the local repository in git synchronized with the remote one in CVS.

Daily work

From now on, every change should go in a local git branch. One feature, one branch. For this, I use a work flow described in "A successful Git branching model". The only difference is that master points to CVS, but conceptually the same work flows can be applied here. It is just a convention.

Once your commit is pushed in CVS, it will be back to master in the next update (git cvsimport). Then, you can remove the local branch that implemented that feature.

For work in progress (in local branches), you should rebase them against master. Because you have the features separated, it should be easier to solve conflicts. The tricky part is when some branches depend on others, but still manageable. Micro commits helps a lot (as in any git work flow).

If every local branch is rebased and master never touched (except for updates), then git cvsexportcommit should just work. Remember, it works for one commit. It is a bit tedious, but it is better than nothing. Given the previous example the command should be something like:

$ git cvsexportcommit -vc commit-id

If you only have read-only access to the remote CVS, then you can send the patches by email or make your git repository public, so the commiters can grab your patches to apply them. Nothing different from a normal work flow of CVS in this case. Again, in the next update you will see the changes in master.

Oddson answered 15/7, 2012 at 7:5 Comment(8)
I had to install cvsps on OSX (brew install cvsps). However it's broken by cvsps: bad usage: invalid argument --norc. error. This happens for cvsps 3.x (the option has been removed), possibly downgrading it to 2.x could work, but it could cause other problems.Biagio
@kenorb: git-cvsimport doesn't work with csvps 3.x but 2.x. In order to install an earlier csvps, run brew uninstall cvsps; brew install https://raw.githubusercontent.com/Homebrew/homebrew/5a0b551194b5cf8017478432f8f7e63a77c12bd1/Library/Formula/cvsps.rb NOTE: I'm blind. Didn't see your answer belowHeliochrome
The cvsimport man page is full of warnings, deprecations, and more warnings. It recommends the use of cvs2git instead.Henrie
Sure, 4 years after the original answer.Oddson
Sometimes answers need to be amended when new information becomes available.Henrie
Agreed. As anybody can edit them, rather comment it you could have edited it. couldn't you?Oddson
unfortunately outdatedDome
On Windows, I get git: 'cvsimport' is not a git command.Alisha
B
7

With recent version git cvsimport is broken, because of cvsps tool incompatibility.

So you've to install cvsps-2.1.

On OSX you can (having brew):

brew tap homebrew/versions
brew install cvsps2
brew unlink cvsps
brew link --overwrite cvsps2

And import on empty git repository as usual, e.g.:

git cvsimport -C RepoName -r cvs -o master -k -v -d:pserver:[email protected]:/cvsroot/path ModuleName

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.

Biagio answered 18/3, 2015 at 13:46 Comment(1)
brew tap homebrew/versions throws Error: homebrew/versions was deprecated. This tap is now empty and all its contents were either deleted or migrated. nowdaysAttribution
T
2

I believe there is no ready to use recipe in your case. But, you can try following:

  • Manually synching CVS data with Git, or write scripts for that. They will get information from CVS and put it to Git. This will give you some kind of history in Git. Not fully clean, not fully usable, but still.
  • Migrate your CVS repository to Git using tools like git cvsimport. And ask Git to pretend to be CVS for other developers, using git cvsserver.
Tolley answered 10/7, 2012 at 13:46 Comment(1)
Here the success story of migration to Git from CVS: https://mcmap.net/q/277036/-how-to-import-cvs-to-git-scm/1047741Tolley

© 2022 - 2024 — McMap. All rights reserved.