3

We are moving from a svn repository to a git repository

Although the svn trunk was migrated, the branches were not(svn server is maintained by a different team).

So I am left with a local copy of svn branch which is almost 6 months older than the current git repository.

If you want to ask why 6 months, it was a huge feature so 2 months went into development and rest 4 months were wasted because the feature could not be released due to some blockers.

How can I now merge my local svn branch which has these bunch of changes on 6 months old code to a git branch ?

adi rohan
  • 796
  • 1
  • 10
  • 26

1 Answers1

3

You could

  • git-svn that SVN repo into a git repo
  • add that new git repo as a remote of your existing git repo and fetch it

    cd /path/to/existing/repo
    git remote add gitsvn /path/to/gitsvn/repo
    git fetch gitsvn
    
  • create a new branch in your current Git repo at a point you estimate that 6 month effort might have started

  • cherry-pick the fetched commit onto that new branch
  • finally, merge that new Git branch in your master branch
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Well, I will try this. But are there any chances of loss of code ? – adi rohan May 12 '17 at 05:07
  • 1
    @adirohan no, the code will be there: only the merge should be done carefully in order to properly integrate the two histories. – VonC May 12 '17 at 05:20
  • "add that new git repo as a remote of your existing git repo", I am new to git. How do I do this ? – adi rohan May 12 '17 at 08:12
  • @adirohan I have added the commands, but don't forget to click on the links present in said answer: they do add to the explanations. – VonC May 12 '17 at 08:21
  • Ok, I have reached till the cherry pick point. I use source tree; I dont see any remotes named gitsvn in there or in my local branches. How do I cherry pick ? – adi rohan May 12 '17 at 10:24
  • @adirohan gitsvn is just an example, as a name for your remote (in `git remote add gitsvn /path/to/your/git/repo/imported/from/svn`). Check first that you have two remotes in your current repo (in command line: `git remote -v`) then go back to your GUI (here SourceTree) and check you automatically refresh those metadata: see https://confluence.atlassian.com/sourcetreekb/refreshing-repository-according-to-file-changes-and-remote-changes-on-sourcetree-785323792.html – VonC May 12 '17 at 10:47
  • What if I do this: After adding a new remote to gitsvn, checkout as local branch then push it to my origin remote. I can then merge it to my origin master ? – adi rohan May 16 '17 at 13:40
  • @adirohan you could, but if you already pushed to origin/master, you wouldn't need to merge to origin/master – VonC May 16 '17 at 13:43
  • I meant push as a new branch to my origin not directly to master. Will this have any consequences to my history ? – adi rohan May 16 '17 at 13:57
  • No, once you have imported from SVN, you can what you want with your Git repo. – VonC May 16 '17 at 16:03