Search code examples
gitgit-svn

Disconnected GIT branches after migrating from SVN


Tried to see few dozen posts and still not getting what I want.

Preface: We initially had a very big SVN repository with no trunk (standard structure) etc. So, the project I was working had no structure too (inside the sub-folder). I worked on this project for about couple of months and then came across a situation where I needed a branch for production fix. So, I restructured only my project code into trunk, tags and branches (i.e. sub-directory within the SVN repository). Then from history I created a branch named Live and did a fix for production and deployed it. I then merged this fix into my trunk with no issues. We kept on working on trunk and also kept on deploying, but due to unnecessary complexities of SVN didn't merge trunk to Live even though we had few deployments. (This is all in SVN)

Migration: We recently decided to setup a new TFS server and have our version control via GIT. So, after the installation was done, I had a task to migrate the code only for this project to GIT. I started doing it on my local PC using "git svn clone" and was happy to see all my history was migrated. Have branches as:

  • master: originated from trunk and I can see the history from the time I had re-structured it in SVN.
  • Live: Goes back from the beginning of the SVN repository (project folder creation date) and marked as branch name properly.

The problem is the branches are disconnected (no joining node) :-(

Please see image below:

enter image description here

As per the above image, the master branch starts at the highlighted commit (node) but Live branch just starts from the SVN 1st commit.

Ideally I would have wanted to have everything on master and Live shown as branch from master when it was really created. Also, when I try to checkout Live branch, I get warning that it is detached HEAD and I may not get/push the commits to master (i.e. HEAD) branch.

Can someone send me the steps to fix this scenario, please?

Possible solution, I think:

  • Rename the master to svn-trunk and Live to SVN-Live
  • Then create a branch named master from SVN-Live (will it have any conflict at remote?) at the commit when I had done restructure (one before highlight i.e."Live 2656").
  • Merge SVN-trunk on Master.
  • Create new branch named Live from this HEAD (as currently the final code is in production).

The process may impact negative, so I'm cautious.

  • My only worry is will it allow me to merge the commits from disconnected SVN-trunk to my new master? (Right now Git Extensions show me the option to merge Live to Master but not other way round.
  • Also, if I do trial and error locally and screw up things, how should a reset back to current state?

Update: Renamed the branches and Created master based on the "Live@2656". Now, trying to merge "Svn-trunk" to master (new branch) - I get below error:

fatal: refusing to merge unrelated histories
Done

Solution

  • Maybe start form a fresh git svn clone as it may save some headache. Also it is not a bad idea to keep a copy of such acquired git repository somewhere safe :)

    Still there are two ways you may try...

    Possibility #1 - fix the structure

    A cleaner way would be to reconstruct the real structure of the repository. If I understand correctly, trunk was created at some point in history. If you are able to find that spot in the history you may be able to use git rebase <SHA of that spot in branch Live> to reconnect the histories together. Some conflicts may appear, though.

    However, if you have merged some development progress back to Live while on SVN you may have a hard time while merging. To circumvent this you may reconstruct these merges as proper merge commits but it may not be worth the time if you do not have to have a proper history...

    Possibility #2 - just rebase

    Or a much simpler solution if you do not care about the proper history at all...

    git checkout master
    git rebase Live
    

    The only thing you need to be certain about in there is the resolution of possible conflicts.