Search code examples
gitsvnversion-controlgit-svn

merge from svn to git, commit by commit


Our company has two repositories, svn repository(trunk) used for development of one product and git repository(master) used for deployment of several products(teams). Our team wants to merge from svn subdirectory "trunk/web" to git subdirectory "master/product-a/web-dev".

Those repositories have different source codes with a different tree structure, but two subdirectories we want to merge have almost same source codes inside. Also, they're not linked in any way, and we need to merge manually for now. Git repository is shared by other teams and we cannot build it from scratch(cannot make big changes that might stop daily development&deployment).

Is it possible to merge from svn subdirectory to git subdirectory, commit by commit, in specified revision rage automatically(by a few commands or a long program)? We need to merge commit by commit with commit comments, so that we can trace changes on git by redmine issue number used in svn.

I'd appreciate any help, thank you.


Solution

  • I resolved the issue by the following step:

    1. Create diff patch for Git by SVN

      svn diff --git -r 12345 > /tmp/12345-fileName.txt
      
    2. Modify paths in patch text file to resolve the path difference between SVN and Git
    3. Apply patch on local Git repository

      cd /path/to/local/git/repository & git apply /tmp/12345-fileName.txt
      
    4. Commit on Git

      git commit
      

    I ran a Java program to generate and execute those commands, and repeated the steps above, revision by revision, to merge specific range of revisions from SVN to Git.

    I understand this is not a good practice, but I had to solve the ongoing problem without a big change in version control systems. Thank you all for your advices.