Moving from svn to git

When working with JDeveloper you’ll have the option of use “Version Application” to drop everything into a Subversion repository.

BUT! … if you, like me, would rather use the command line for your version control stuff (and lots of other stuff). Then that … why not.

Using svn from the command line is an option just remember to set your svn:ignore accordingly (see my post about this).

But – since we’re having fun – why not try out git instead?

git is a household name amongst Open Source developers. Especially since GitHub is freely available.

But you don’t need to drop all your code at GitHub to use git. You can use a Subversion repository. This is great for all us git-users who are expected to drop all code into the corporate SVN.

Git has a svn-plugin that allows you to use git for checkout and checkin to SVN. So after a clone from svn (see below) then you use git to commit code locally. Once you’re ready to push to central repository then the commands below should do.

Note that normal git-rules apply. No uncommitted changes are allowed in a git repository when the svn-plugin commits (which is what git stash is great for).

A note on branching

Using local branches is a great way to separate your work from the svn-master branch.

git checkout -b branchname

The svn-based master-branch is important and needs a little bit of extra care – compared to a standard git-branch.

This has to do with the differences between svn and git – and some limitations in git-svn. Basically you should avoid doing drastic git-magic such as updating checkin-comments on stuff committed to svn. And keep the master as a linear string of commits … which will make life simple for git-svn.

But you can checkout to a local branch – and then merge back into the master branch afterwards (either as a string of commits or squash all local commits into one big commit on the master-branch).

The Commands

Checkout / clone
$ git svn clone --branches branches --tags tags --trunk trunk \
http://a.svn.repository.url.just.as.in.svn LOCAL-REPOSITORY-NAME

or
$ git svn clone -s http://a.svn.repository.url.just.as.in.svn LOCAL-REPOSITORY-NAME
if your repository follows standard.

Checkin

$ git svn dcommit

Update from SVN without checking in your code

$ git svn rebase

Commit to SVN with uncommitted local changes
This happens once in a while – that someone you to make a quick change and commit it. So you’re happily working on a branch when a colleague ask you to do a quick change to a file. Here’s what I’d do:

(close JDeveloper to ensure that all project changes are saved)
$ git stash 
$ git checkout -b quickchange master
(restart JDeveloper and make the changes...)
...
(work ready now commit to the local branch)
$ git commit -m 'Some comment on the changes made'
(return to the master branch)
$ git checkout master
(pull the change into the master branch)
$ git merge quickchange
$ git svn dcommit 
(return to the stuff you were working on before the interruption)
$ git checkout work
(return the uncommitted changes)
$ git stash pop

See more on git-merge at the offical documentation home.

Remember to close JDeveloper during git checkouts – just in case.

If the change you’ve made on master is needed in your current work you can rebase the work-branch

$ git checkout work
$ git rebase master
This entry was posted in Git and tagged , , . Bookmark the permalink.

Leave a Reply