Search code examples
gitmigrationcvsgit-merge

How to import non-version controlled branches to git?


We used to use CVS in our team and we are trying to migrate to git, but for some strange reason one of the programmers has been working on a big project by manually updating the branches instead of using version control. This has led to many human error discrepancies in the code and we're not sure where to go from here.

Right now we are waiting on that programmer to consolidate those branches before importing to git, but it is taking way too long. We are considering importing all the branches separately and then merging them in git. We're just not sure how to do this with non-version controlled branches.

What is the best way to go about this?


Solution

  • Here is one way you can try to solve your problem. Assuming you are beginning on your master branch, first create a new feature branch which will hold the programmer's manual version of the project:

    git checkout -b feature
    

    Next, you can copy the root directory containing the programmer's project and paste it on top of the root of the feature branch you just created. I see three possibilities happening with each file:

    • a new file which only the programmer had will be added
    • a shared file will be overwritten by the programmer's version
    • a shared file will added in a location different than its location in the feature branch

    Take a deep breath, and type git status from the Git console. You will likely see evidence of all three scenarios, possibly also including directories. Pay attention to what you see, because you will be dealing with these files in the final step.

    Next add every file to the Git index and commit via

    git add path/to/file
    git commit -m 'programmer branch created'
    

    Don't be afraid to use wildcards if that speeds things up for you, e.g. git add dir/*

    Now you have a bona-fide Git feature branch representing the work which the programmer did. For the final step, you can try merging thigs branch into master via:

    git checkout master
    git merge feature
    

    There will be lots of conflicts, but if you apply some insight you should be able to determine a plan for resolving them.