Search code examples
gitgithubversion-controlcvs

Import only history from CVS repository into already created git repository


At work we have a CVS repository that has commits stretching back nearly 15 years. A couple of years ago that repository was converted to git and uploaded to a public GitHub repository. However, the git repository was just initialized with the current version of the files, no history was imported (not my doing). The CVS history is straightforward and linear--we never used CVS branches. It is not a highly-active repository: there have been only about 25 commits to the public git repository since it was created.

I would like to be able to import the CVS history into the existing git repository without necessarily creating a new repository. From what I've read in the documentation for git-cvsimport or cvs2git, those tools always create new repositories. Alternatively, I could do a fresh cvs/git conversion and upload the new repository in place of the current one, and apply the 25 post-cvs commits. Is this possible, and if so, what is the recommended way to do this? I have read & write access to both the CVS and git repositories, and server access to the CVS one if necessary.

I am fairly comfortable with simple git branching, merging, and rebasing, but I would not say I am an expert (I consult the Pro Git book a lot).


Solution

  • I think the solution is to create temporary branch ("start") from the first commit in the master branch, then generating and importing history from CSV into another temporary branch ("import"), merging with strategy ours from the "start" branch and merging from "master" branch the newer commits and renaming the "import" branch to "master":

    # create new git repository by running cvs2git in import-git-path
    # change directory to your current repository
    git log
    # find the first commit
    git checkout -b start "first-commit"
    git checkout --orphan branch
    rm -rf * .gitignore # or any other file
    git add -A
    git remote add import-repo import-git-path
    git pull import-repo master
    git merge -s ours start
    git merge master
    git branch -D start
    git branch -D master
    git branch -m import master