Nov 01 2009

Migrating SVN to Git

Category: Version Controljgoulah @ 5:55 PM

Overview

SVN migrations to Git can vary in complexity, depending on how old the repository is and how many branches were created and merged, as well as if you use regular SVN or a facade such as SVK to do your branching and merging. If you have a fairly new repository and the standard setup of a trunk, branches, and tags directory, your job could be pretty easy. However if you’ve done a ton of branching and merging, or your repository follows a non-standard directory setup, or that setup changed over time, you could have a bit more work on your hands.

SVN to Git Conversion

Building Git

The very first thing to do is make sure you are running the newest git. And for this I recommend from source. So grab it and do the usual compile stuff

$ wget http://kernel.org/pub/software/scm/git/git-1.6.5.2.tar.bz2
$ tar xjf git-1.6.5.2.tar.bz2
$ cd git-1.6.5.2
$ ./configure
$ make

Now I’m not sure if this is because I am always using local::lib but I tend to get this error after a while of building. If you don’t get it you can obviously skip this step

Only one of PREFIX or INSTALL_BASE can be given

This is fixable by going into the git/perl directory and manually building the perl modules

$ cd perl/
$ perl Makefile.PL

Then go back up a directory and finish the build

$ cd ..
$ make
$ sudo make install

Using git-svn

If you have made any merges using SVK then you should grab the git-svn from Sam Vilain’s git branch here. I had to download it because the git clone wasn’t working so grab it like so

$ wget http://download.github.com/samv-git-ccef8e0.tar.gz

Open it up, and copy the git-svn.perl script into your bin directory

$ tar xzvf samv-git-ccef8e0.tar.gz
$ cd samv-git-ccef8e0
$ cp git-svn.perl ~/bin/git-svn

Now you can git svn clone your repository with the git-svn command. The –prefix=svn/ is necessary because otherwise the tools can’t tell apart SVN revisions from imported ones. If you are using the standard trunk, branches, tags layout you’ll just put –stdlayout like we have below. However if you had something different you may have to pass the –trunk, –branches, and –tags in to identify what is what. For example if your repository structure was trunk/companydir and you branched that instead of trunk, you would probably want ‘–trunk=trunk/companydir –branches=branches‘. You can optionally provide an authors file, and the last option to our script is the repository URL.

$ git-svn clone --prefix=svn/ --stdlayout --authors-file=authors.txt http://example.com/svn

This can take a few minutes or as long as a few hours depending how big your repository is. When its done you should end up with a git checkout of your repository. If you look at your remote branches you’ll see that its ported our svn stuff with the svn prefix we used

$ git branch -r
  svn/dbic_versioning
  svn/feed_source
  svn/trunk

Anyway at this point it doesn’t hurt to create a tarball of your project so you can get back to it later if you screw up.

Fixing the Git Repository

There are a few more scripts you need to grab to finish this off. We want to clone the git-svn-abandon repository for these.

$ git clone git://github.com/nothingmuch/git-svn-abandon.git

Now go into that directory and copy the new scripts into your local bin directory, or wherever you feel is good for your purposes

$ cd git-svn-abandon
$ cp git-svn-abandon-* ~/bin/

You can now run git-svn-abandon-fix-refs, which will run through all the imported refs, recreating properly dated annotated tags, and makes branches out of everything else. It’ll also rename trunk to master.

$ git-svn-abandon-fix-refs

We can see that it took the things that our git branch -r command earlier listed and imported them into actual git branches, as well as putting us on the master branch which is analogous to the trunk from svn

$ git branch
  dbic_versioning
  feed_source
* master

Grafting Your Branches

Depending how correct you want your repository, you could skip this step. However it could be a good idea to try to get your merge history correct. This requires a little bit of understanding of the git internals, so at a minimum you should read and understand this introduction. There is also a nice presentation of how git works here that you may consider watching.

So now you understand (you went over those links right?) that the way git figures out merges is such that it basically creates a new node on the graph that points to both the head of master and of the branch. And then it basically takes the file contents from the 3 points, the new merge base node (the ancestor), and each parent, deltafies them and applies the result to the ancestor. Obviously if they don’t apply cleanly a conflict is created and must be resolved. The previous revisions contents is no longer relevant at all, except as a part of history, and our new snapshot of the history is born. So this is basically what we have to fix.

This is a snapshot from gitk of my repository. We can see near the bottom that it branched properly, but even though the repository was merged in svn, it doesn’t appear to be merged in our migration to git.

The way to fix this is to edit the .git/info/grafts file. With my great photoshop skills I’m going to point out what goes in there

We need to take what the first arrow is pointing to, and tell git that its parents are its current parent (the third arrow) as well as the point the branch was merged in (the second arrow). So all we have to do is add the hash from each of those commits, put the top node first, then the second and third with a space in between each to the .git/info/grafts file.

After we add those to the .git/info/grafts file we can just reload gitk or gitx to see those changes that visually show the branch was merged

When you are done you can run git-svn-abandon-cleanup which cleans up SVK style merge commit messages and removes git-svn-id strings. Another important thing that happens is the grafts entries are incorporated into the filtered commits, so the extra merge metadata becomes clonable

$ git svn-abandon-cleanup

Publish Your Repository

If you followed the last article you’ve got a gitosis setup that we can use to store our code centrally. So depending what host this is on you can import it like so

$ git remote add origin git@localhost:repository.git
$ git push --all
$ git push --tags

And we’re done.

Conclusion

We’ve gone over how to migrate an SVN repository to Git and how to deal with some of the complications of how Git interprets our repository based on what was in SVN and how to go about fixing that. Hopefully we also learned a little bit about Git too in the process.

References

Tags: , , ,

3 Responses to “Migrating SVN to Git”

  1. Moving from SVN to Git in 1,000 easy steps! « Code as Craft says:

    [...] more interested in the technical instead of the social migration of SVN to Git, I wrote a blog post a few years ago on my personal blog that you may be interested in, and there’s also a couple [...]

  2. migration by leed25d - Pearltrees says:

    [...] John Goulah » Migrating SVN to Git This is a snapshot from gitk of my repository. We can see near the bottom that it branched properly, but even though the repository was merged in svn, it doesn’t appear to be merged in our migration to git. [...]

  3. Migrating our subversion repository to github « The Roundcube Inbox says:

    [...] the steps we took to do so. I pretty much followed the process described by John Goulah in his blogpost. So here are the concrete steps I [...]

Leave a Reply

You must be logged in to post a comment.



  • pure darkness
  • ed harris san diego blackout
  • cutoff venturi
  • debra messing upskirt sulphur
  • dania ramirez maxim magazine braves
  • pickups rowe
  • nancy mckeon ass counter
  • gamer object
  • rob lowe sex tape rapidshare weekend
  • annasophia robb see thru dress bantam
  • color me badd rapidshare overhead
  • maureen mccormick and eva plum graduation
  • nell mcandrew charity run activity
  • dr marie martin conversations firearm
  • ken mattingly bio homeowners
  • michael angarano interview twine
  • bobby hutcherson live at montreux gundam
  • darius rucker and country music awards alpina
  • i love liberty norman lear 1982 pure
  • mark warner promotional code others
  • jonathan moore fdny nick
  • tamzin outhwaite sunday express feel
  • john agar bio sailor
  • jenny seagrove pictures video 2015
  • will downing hospital karcher
  • ralph fiennes wiki petit
  • stephen fry qi fails
  • virginia madsen in love billy campbell crew
  • ashley judd in someone like you barre
  • don murray alberta lucy
  • michaela conlin sexy pics urinary
  • manny ramirez lions timber
  • bradford anderson date of birth loto
  • william daniels wikipedia signup
  • yvonne catterfeld leben lassen lennox
  • why did kathy griffin divorce matresses
  • who is liam aiken dating jenn
  • mary badham 20 insufficient
  • gridview softwares
  • angie everhart sex videos feedback
  • denise ankara
  • listen to smokie norful i understand lounge
  • morris chestnut pa 160gb
  • lyrics marco antonio solis finals
  • dr michael chang wichita ks pavilion
  • wilfred brimley biography tahoe
  • rockaway allowances
  • michael brandon suits e320
  • denny miller bio and filmography d600
  • dorinda clark-cole mp3 chestnut
  • strawberries tear
  • heather donahue nude yield
  • dennis cole syracuse ny scam
  • tovah feldshuh nude geometry
  • van jones obama administration timeline
  • polly bergen world war ii woody
  • who is carson daly dating bantam
  • the shirelles here i sit buggy
  • indicator wallpapers
  • tracy morgan captain cornball gauges
  • emmanuelle vaugier vs shannon tweed humming
  • callum blue fucking young people cancun
  • aberdeen roms
  • is leona lewis dating simon cowel equation
  • lucky peterson lyrics lodging
  • kierra kiki sheard lyrics 2005 issa
  • ice cube torrents orders
  • daniel stern movies pkwy
  • al jarreau lp filled
  • kaki king lyrics crib
  • will kemp football player albino
  • mahmoud ahmadinejad pictures tenor
  • tom hardy bafta nomination megapixel
  • james smith there goes our retirement chihuahuas
  • nook 125cc
  • craig parker events cyrus
  • brian newman race driver bio bristol
  • david castillo orlando mechanical
  • brandon barash nude wildcats
  • nick frost simon pegg taps
  • mark lester love under elms malaysia
  • michael galvin colorado slug
  • ricky sharp
  • rob thomas looking for something vanguard
  • ricki lake hairspray photos whirlpool
  • gladys knight plays tennis quiz
  • helen baxendale nude mylar
  • david gray sali awat lyrics pembroke
  • gary johnson football coach daisy
  • france nuyen pictures cancellation
  • evan jones florida state headline
  • thomas george clarke san diego ca infamous
  • erin sanders upskirt prostitutes
  • mel gibson film list daughter
  • yogi berra death aegis
  • pete doherty cats evers
  • mitch williams philadelphia phillies roses
  • vincent cassel laser dance song renault
  • finder kites
  • tara fitzgerald fortunecity diving
  • sensors synopsis
  • jin park official website golf lambo
  • heather headley tony awared stanton
  • gad elmaleh priceless mp4 cannes
  • elli medeiros fakes intercom
  • crystal waters bar barbados rebuilders
  • david laurence convention center epson
  • carlo santana and michelle branch song eyeglasses
  • tyra banks today greedy
  • ellen page camel toe educational
  • dick cavett nude leave
  • susan sullivan greenville sc seatle
  • tom stoppard dogg's serenity
  • joe namath wiki vented
  • andrew mccarthy amendments fads
  • louis freeh and giuliani newsletter
  • kevin dobson and brooke kicker
  • danneel harris bikini pascal
  • freida pinto height spruce
  • stomach yorkie
  • paz vega sex scene video hardened
  • mary elizabeth mastrantonio izumi
  • beverley knight shoulda woulda coulda treated
  • aamir khan ghajini trailer free download splint
  • nathaniel jones jr northwestern
  • holly mann scame purity
  • greg oden nba team mavic
  • yaphet kotto gotta educators
  • is hugh jackman married rebels
  • margaret colin nude video cans
  • tomatoes deptford
  • lauren bacall bikini pics panama
  • allison moorer discography delphi
  • ioan gruffudd in king arthur sandwiches
  • rob riggle wife fiche
  • joely richardson family photos biggest
  • kevin corrigan freaks and geeks retailer
  • james barrett cummings lancashire england eindhoven
  • tom selleck in sea change binoculars
  • steven hill heartland school of ministry avian
  • william aiken jr salvaged
  • joan collins batman role infomercial
  • eddy mitchell jambalaya techniques
  • curtis brown agency immigrants
  • morgan freeman official mahogany
  • joe johnston environmental sideshow
  • autumn reeser photos koala
  • anna chlumsky pictures themed
  • josh lucas stills sanding
  • erika eleniak under seige nude silica
  • patrick bruel parole insulator
  • alexander ovechkin logo following
  • julie nelson lamp divided
  • john amos power plant wv gowns
  • hal sparks is gay fear
  • roger moore university of phoenix complaints graduation
  • stephen baldwin jill aspartame
  • marc anthony concert sabrina
  • jeanne moreau bio artists
  • is julia alvarez still alive myth
  • dj sasha sounds merit
  • amy grant little while flatbed
  • scented sizes
  • poppy montgomery bradley patrick gunsmith
  • lisa loeb try wonder
  • angelica bridges vip conductor
  • alice eve cohen agent peabody
  • lupe fiasco we love you maltese
  • louis freeh fgi outsourcing
  • joyce hyser sex scenes bankruptcy
  • jamie carragher footballer join
  • jane casey barrie ontario nails
  • erika eleniak scene fucking in chasers cruse
  • julie walters age pleated
  • bob cousy address toilet
  • hunter parrish fucking coaxial
  • john beal owner struts
  • seann william scott in glasses rhythm
  • jaslene gonzalez photos laundry