How to use a CVS server from a git client

First Checkout

  • We need 2 repos, one for git and one for cvs but we don’t touch cvs one ever
  • repos/MODULENAME

git cvsimport -d server:/path/to/cvs -C repo/MODULENAME -r cvs -k MODULENAME
cvs checkout -d cvs/MODULENAME MODULENAME

Create a new branch to work

git checkout -b non-master-branch-name

Tweaks for automatic updating

modulename, cvs and the $CVSROOT contents

git config cvsimport.module MODULENAME
git config cvsimport.r cvs
git config cvsimport.d server:/path/to/cvs

Updating the code

git checkout master
git cvsimport
git checkout non-master-branch-name
git rebase master


  • Create another branch, DON’T WORK ON MASTER branch,use it only for updates, rebases and commits.
  • Steps:

    • Modify the code in non-master branch and commit there
    • We may have several commits in our non-master branch, some of them we want them in master and others maybe not, we need to tell to cvsexportcommit from which commit to which commit we want to export, so lets say the master and non-master branchs were synced and that we commited a single commit to the non-master branch and we want it in the cvs
    • First we need its commit-id and the commit-id of the previous one
    • arkaitzj@zack:~/repos/module$ git log  --pretty=oneline -n2
      60e3c17262aa67adece8070e1b47e819353b778c Test improvements                           #Last commit
      3ee1411a952b81ff70bcbf0219852b70cccd67f0    Softwaretest needed Makefiles added  #Previous commit, exists in both branches
  • Now we export to cvs the changes on those commit
  • -w parameter marks the path of the cvs checked out code, no need to touch it but needs to be there for cvsexportcommit
  • -u ensures the cvs repo is updated before diffs applied
  • -p makes diff reject dubious patches Remember to always update before exportcommit
  • -c if the patch was cleanly applied it is committed to cvs automatically
  • arkaitzj@zack:~/repos/modulename$ git cvsexportcommit -w ../../cvs/modulename -u -p -c   3ee1411a952b81ff70bcbf0219852b7 60e3c17262aa67adece8070e1b47e
  • Committed, next time we do a cvs import on master branch we’ll get the changes from the CVS server, but still we need an extra step
  • As cvsimport and cvsexportcommit don’t play well for the moment they don’t recognize each other commits, so once we’ve committed something from non-master branch we still have to do 3 things, remove the commit from non-master branch, cvsimport the last change to master branch and rebase non-master branch to master

Let 10 minutes pass from the cvsexportcommit to the cvsimport, if you don’t see your commit on master history after cvsimport wait a little more and cvsimport again

#non-master branch
git rebase -i HEAD~2 # Find the last commit(what we sent to CVS) and remove that line, this will erase that commit form history
#Checkout master branch and cvsimport
git checkout master
git cvsimport
#Now we have imported our commit from the CVS and it is valid history of the master branch, checkout non-master and rebase
git checkout non-master
git rebase master
  • Use this script, it’ll warn you on commits and you’ll know wich branch are you committing to. place it in DEST_DIRECTORY/.git/hooks/pre-commit
arkaitzj@zack:~/repos/module$ cat .git/hooks/pre-commit
NC='\e[0m' # No Color
BRANCHNAME=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')

exec < /dev/tty
echo -e "Committing to branch $RED$BRANCHNAME$NC. Commit (y/n): "
read response

if [ "$response" == "y" ]
       echo "Committing...."
       exit 0
       echo "Commit ABORTED"
       exit 1

One Response to How to use a CVS server from a git client

  1. […] This post was mentioned on Twitter by Toni, james LL. james LL said: How to use a CVS server from a git client « Arkaitzj’s Blog never using #cvs again […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: