Some complex subversion merges are coming up in my project: big branches that have been apart for a long time. Svn gives too many conflicts - and some of them seem spurious.
Given that git
is praised for a superiour merge experience,
Would it be any good to use git-svn
just for the benefit of making the merge more manageable?
Can you recommend other alternatives (eg. svk
, hgsvn
) to lessen the merge pain?
Some conflicts are easy enough to resolve (e.g java imports, whitespaces) - so I'm also wondering if there is any automated solutions for those.
A full switch to DVCS might happen in the future (some of us would love that), but not right now. (UPDATE: this isn't true any longer - the team switched fully recently and are happy about it).
Thanks in advance.
PS: there are posts that seem to be related (eg. git-svn merge 2 svn branches) but they don't fully answer this question.
Update: see my -novice- answer after going down (and up:) this road.
Trying to answer my question: using git for svn merges seems promising.
Update: it's not just promising, it's a great success. In short, Linus was right.
Just completed a huge merge of 2 svn branches that have been apart for 1.5 years; 3k files were changed, got tons of conflicts in svn (~800 I think).
I found git & git-svn a life saver:
git-log
(and the underlyinggit-rev-parse
options), nothing can be more powerful than this. It's handy as well:-p
gives you diffs in one go; in svn you get a log, then find the diff for that "revision-1:revision", or use clumsy UIs. Find when a string was added/removed into the repo, search multiple branches simultaneouslygitk
: hugely useful for visualising branch histories, combined with great search capabilities. Haven't seen anything like this in other tools, especially not as fast as this. Nevermind it's in Tk, it's just brilliantgit gui
: works fine even if not the sexiest - great help for the novice to discover thingsblame
: a miracle. Yes, it detects where the original segment comes from (copy&paste etc)mergetool
: much more pleasant experience than kicking off the bigsvn merge
which then stops everytime (ie. every 5 minutes) it runs into a conflict, press '(p)ostpone', than manually hunt for conflicted files later. Preferred a flavour of this integrated ingit gui
(needed a tiny patch for that). Found integrating external diff tools better configurable than insvn
.rebase
allowed to filter out messier parts of the svn historySo, this really can make the difference from a nightmare to joy - especially if you enjoy learning (which does take some effort in this case - I guess like learning a motorbike after a bicycle).
Even though I can't force everyone in the company to switch immediately - I really didn't intend to actually. Again,
git-svn
saves us by 'dipping the toe first' approach.. But seeing colleagues' reactions the switch might happen much before anyone expected:)I'd say- even if we forget about merges & commits, this stuff is already great as a read-only frontend for queries, visualisation, backups, etc..
Caveat:
Another excellent source is the Pro Git book, section 'Switching Active Branches' basically says that the merge does work, but
dcommit
will only store the content of the merge, but the history will be compromised (which breaks subsequent merges), so you should drop the work branch after merge. Anyway it makes sense after all, and in practice it's easy to avoid traps here.. in svn, I found people do not usually re-merge anyway so this could only be seen as a step back if you come from git world in the first place.Anyhow, the dcommit just worked for me. I did it onto my own svn workbranch that I kept for this only, so avoided any extra conflicts that time. However, I decided to do the final merge from this workbranch to the svn trunk in svn (after syncing up everything in git);
--ignore-ancestry
gave the best results there.Update: as I found out later, the last few steps above (extra svn branch and merge--ignore-ancestry) is easily avoided by just keeping the branch you're dcomitting from linear. As Gabe says below,
merge --squash
just creates a simple stupid svn-friendly commit. Just when ready with huge merge(s) on the my local branch (which might take days/weeks), I would now just:I know the merge tracking won't work great from the svn-side, until we switch fully. I can't wait for that.
UPDATE: @Kevin requested some more details on the whole process of merging svn branches.. There are lots articles, posts out there, but as a novice I found some of the confusing/misleading/out of date.. Anyhow, the way I do it these days (of course, stuck with git-svn after that merge affair; just as some newly infected colleagues)..
Actually I preferred to use 'git gui's builtin mergetool integration (right click on file in conflict). That's slightly limited though,so see my little patch above, which allows you to plugin a shell script where you can invoke whatever mergetools you prefer (I tried a variety of them sometimes in parallel as they caused a surprising amount of grief.. but normally I'm stuck with kdiff3..
When a merge step goes fine (no conflict), a merge commit is done automatically; otherwise, you resolve conflicts then
The last phase.. Note that so far we had only local commits, not talking to the svn server yet. Unless you've used --squash or other tricks, you now end up with a graph where your merge commit has 2 parents: the tips of your svn-mirror branches. Now this is the usual gotcha: svn can only take linear history.. so 'git-svn' simplifies it by just dropping the second parent (svn-branch-to-merge in the above case).. so the real merge tracking is gone on the svn side..but otherwise it's fine in this case.
If you want a safer/cleaner way, this is where my earlier snippet comes in: just do the final merge with --squash. Adapted the earlier one to this flow:
oops, this is getting way too long, stopping before too late.. Good luck.