Home > Git > Fighting with git svn

Fighting with git svn

First up, a disclaimer – I am a git n00b therefore anything below may or may not be correct but “it works for me” so I am putting it out here for anyone else facing similar issues ( and also for future reference as I have a feeling this will happen a few more times yet ).

I have recently moved to using git on my laptop. Originally I installed GitExtensions ( which uses msysGit 1.6.3 ), but after some problems I uninstalled that and installed msysGit 1.6.4 using this excellent guide from Jason Meredith.

I cloned the repository I was working from using:

git svn clone https://<server>/svn/<projectname>/trunk

I didn’t need all of the branches so I only grabbed the trunk. My upstream repository is a subversion repository hosted within Visual SVN Server 2.05.  After cloning the subversion repository I wanted to work on, I started working as usual with the following workflow:


git checkout -b
... work work work ...
git commit -a -m ""
... more work / commit cycles ...

Once I had completed the task ( integrating the spark engine as it happens – what a joy to work with that is ), I jumped back to the master to commit my changes back to the upstream repository. I rebase the changes from my topic branch onto the master so that I end up with a linear commit history that doesn’t confuse git svn.


git checkout master
git svn rebase
git rebase
git svn dcommit

And this is where the trouble started. git svn completed the first commit of 4 and then decided there were no more changes between current head and refs/remotes/git-svn so it reset to the latest refs/remotes/git-svn and left me with a number of unstaged files that made up the changes for the remaining 3 commits. Poking around with git log showed me that git still had the commits in master but I could no longer dcommit them due to git and svn being out of sync.

To clean up git I reset master to the last committed svn revision and then removed all of the git commits after that using a combination of git svn reset -r , git reset –hard and git clean -f ( I can’t remember the exact sequence of commands so I won’t post them just yet ). Once I had both git and git svn synchronised back to the point of the last commit, I cherry picked each commit from the topic branch and dcommitted them one at a time to the remote subversion repository:


git checkout
# Use this to get the sha1 commit tags of the commits to cherry pick
git log
git checkout master
# Repeat the following for each commit on the topic branch that needs to be dcommitted
git cherry-pick
git dcommit

This is essentially the same as git rebase / git svn dcommit except you are pulling the commits one at a time.

While I still don’t understand why git svn dcommit refuses to work for multiple commits, at least I can continue using it to work offline, although I think I’ll be using git merge –squash going forward.

Advertisement
Categories: Git

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.