简体   繁体   中英

merging svn-based fork of git project back into git

I am developing a project in git. Someone else has taken a snapshot of my project and continued development in svn. Now I want to merge changes from svn back into git.

Is there an easy way to merge changes from svn into git? The best I can come up with is creating a new git branch and manually adding all of the files in.

My understanding of git-svn is that it creates a new git repo based on the svn repo. The documentation also says "don't push to a parallel Git repository to collaborate with fellow Git developers at the same time", which sounds exactly like what I want. The only simplification is that I do not need to write anything into svn; changes are moving from svn to git only.

I would avoid any fancy tricks and keep it simple.

Just create a new branch in git. Next, overlay (copy) the files from the svn branch into your git branch. Commit your changes.

I like to use the visual kdiff3 for merging two folders, since I assume you want to cherry pick changes. However, there are lots of great tools for merging two similar folders.

Once the files are overlaid on top of your git files, you have a final chance to review changes before committing. Atlassian Source Tree is a great tool for reviewing changes visually, but again there are lots of great tools out there.

You need to be aware, that using git-svn the history of the svn-branch will most likely not join up with your git history. So here's what you need to do.

  1. Use git-svn to create a (new!) git repo from your svn.
  2. Add your git repo as a remote
  3. Have a look at the history – maybe there is some magic and the histories join up. If so, you are done.
  4. In both repos find the point where the histories diverged. Note their SHAs: OUR-DIV for the sha of the version of the last common commit in your git history, THEIR-DIV for the sha of the version of the last common commit in the imported svn history.
  5. Run git replace $THEIR-DIV $OUR-DIV (see docu of git replace )
  6. make a copy of your svn branch, let's name the new branch svn_branch
  7. Have a look at the new git log and see whether the result is to your liking. If it is, run:

     git filter-branch svn_branch 
  8. You can now push svn_branch to your main git repo

After that, you can not simply import further changes from svn into svn_branch . If you want to that, you need to delete svn_branch , import your changes and then start again from step 6. I am not 100% sure that this will absolutely work, though. Handle with caution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM