merge from svn to git, commit by commit

 ̄綄美尐妖づ 提交于 2019-12-12 04:48:22

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/43922763/merge-from-svn-to-git-commit-by-commit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!