Tried to see few dozen posts and still not getting what I want.
<strong>Preface</strong>: 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 <em>Live</em> and did a fix for production and deployed it. I then merged this fix into my <em>trunk</em> with no issues. We kept on working on <em>trunk</em> and also kept on deploying, but due to unnecessary complexities of SVN didn't merge <em>trunk</em> to <em>Live</em> even though we had few deployments. (This is all in SVN)
<strong>Migration</strong>: 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:<ul><li><em>master</em>: originated from trunk and I can see the history from the time I had re-structured it in SVN.</li> <li><em>Live</em>: Goes back from the beginning of the SVN repository (project folder creation date) and marked as branch name properly.</li> </ul>
The problem is the branches are disconnected (no joining node) :-(
Please see image below:
<a href="https://i.stack.imgur.com/ON6rI.jpg" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/ON6rI.jpg" data-original="https://i.stack.imgur.com/ON6rI.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>
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:<ul><li>Rename the <em>master</em> to <em>svn-trunk</em> and <em>Live</em> to <em>SVN-Live</em></li> <li>Then create a branch named <em>master</em> from <em>SVN-Live</em> (will it have any conflict at remote?) at the commit when I had done restructure (one before highlight i.e."Live 2656").</li> <li>Merge <em>SVN-trunk</em> on Master.</li> <li>Create new branch named <em>Live</em> from this HEAD (as currently the final code is in production).</li> </ul>
The process may impact negative, so I'm cautious.<ul><li>My only worry is will it allow me to merge the commits from disconnected <em>SVN-trunk</em> to my new <em>master</em>? (Right now Git Extensions show me the option to merge Live to Master but not other way round.</li> <li>Also, if I do trial and error locally and screw up things, how should a reset back to current state?</li> </ul>
<strong>Update</strong>: 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 DoneAnswer1:
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...
<strong>Possibility #1 - fix the structure</strong>
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 <strong>find that spot</strong> 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.
<strong>However</strong>, 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...
<strong>Possibility #2 - just rebase</strong>
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.Answer2:
For a one-time migration
git-svn is <strong>not</strong> the right tool for conversions of repositories or parts of repositories. It is a great tool if you want to use Git as frontend for an existing SVN server, but for one-time conversions you should <strong>not</strong> use
svn2git which is much more suited for this use-case.
There are plenty tools called
svn2git, the probably best one is the KDE one from <a href="https://github.com/svn-all-fast-export/svn2git" rel="nofollow">https://github.com/svn-all-fast-export/svn2git</a>. I strongly recommend using that
svn2git tool. It is the best I know available out there and it is very flexible in what you can do with its rules files.
You will be easily able to configure
svn2gits rule file to produce the result you want from your current SVN layout, including any complex histories like yours that might exist and including producing several Git repos out of one SVN repo or combining different SVN repos into one Git repo cleanly in one run if you like.
If you are not 100% about the history of your repository,
svneverever from <a href="http://blog.hartwork.org/?p=763" rel="nofollow">http://blog.hartwork.org/?p=763</a> is a great tool to investigate the history of an SVN repository when migrating it to Git.
git-svn is easier to start with, here are some further reasons why using the KDE
svn2git instead of
git-svn is superior, besides its flexibility:
svn2git(if the correct one is used), this is especially the case for more complex histories with branches and merges and so on</li> <li>the tags are real tags and not branches in Git</li> <li>with
git-svnthe tags contain an extra empty commit which also makes them not part of the branches, so a normal
fetchwill not get them until you give
--tagsto the command as by default only tags pointing to fetched branches are fetched also. With the proper svn2git tags are where they belong</li> <li>if you changed layout in SVN you can easily configure this with
git-svnyou will loose history eventually</li> <li>with
svn2gityou can also split one SVN repository into multiple Git repositories easily</li> <li>or combine multiple SVN repositories in the same SVN root into one Git repository easily</li> <li>the conversion is a gazillion times faster with the correct
You see, there are many reasons why
git-svn is worse and the KDE
svn2git is superior. :-)