Steps for using Git with SVN (Update2)

by rsutton 6. November 2009 04:18

Well I think I may have just become a Git convert today.  Yesterday I began playing with Git and quickly fell in love with how branching works.  I’ve known for a long time that switching to Git at work from SVN would not be reasonable, so I didn’t give it much thought.  Well yesterday I realized that Git can be used quite well with SVN, so here I’ve listed the commands that have made working with Git and SVN quite pleasant.  First I must mention that the best install for Windows is msysgit.  I’ve never been a fan of cygwin, so this gets around using it.

Here is what I do to initially setup the repository.

git svn init svn://myserver/trunk/MyCode
git svn fetch –rHEAD
UPDATE: If you do –rX with X being a previous revision number you will get all the history from that point forward
git svn rebase

To update to the latest just do

git svn rebase

To commit changes to SVN do the following

git svn dcommit

Now here comes the cool part.  When you are working with branches you can create a branch just using normal Git, then when you are ready pull in the changes into your master branch and when you commit to svn it will have a complete log of your changes.  Check this out.

git branch testing
git checkout testing

…makes some changes…

git commit –a –m ‘Testing 1’

…make some changes…

git commit –a –m ‘Testing 2’

Switch back to the master branch

git checkout master

Merge in the changes. 

git pull . testing (or git merge testing)

Send them off to SVN

git svn dcommit

TADAA!!!

Capture

Now this is cool ;)

This and this were very helpful in getting this working.  Thanks!

UPDATE: A couple of additional notes that are helpful.

When updating your code and there are uncommitted modifications.

git stash
git svn rebase
git stash apply
git stash clear

To revert (as they say in the SVN world)

git checkout filename

Tags:

Development

Comments

Comments are closed

Powered by BlogEngine.NET 1.4.5.0
Theme by Extensive SEO

Profile

Member of the Church of Jesus Christ of Latter-Day Saints, Developer and IT Professional