rhythm
rhythm

Reputation: 499

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.

Upvotes: 1

Views: 3336

Answers (2)

rhythm
rhythm

Reputation: 499

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.

Upvotes: 3

Brian Malehorn
Brian Malehorn

Reputation: 2685

Yes, that's possible using git svn. Setup:

git svn clone svn+ssh://user@svn.example.com/trunk
cd trunk
git remote add origin git@github.com:example/develop.git
git fetch origin

This will set up a git repository with one branch named git-svn (svn trunk), and another branch named master (git develop).

Then to apply commits:

git checkout master
git svn fetch
git cherry-pick git-svn...git-svn~10
git push

...this will apply the last 10 commits on trunk and commit them to develop.

Upvotes: 3

Related Questions