tags:

views:

38

answers:

1

I'm just starting with git and using it to interact with an SVN repository. The svn repo is in a standard format so I configured my sandbox as

git svn clone <repo> -s

All seemed fine initially but after several rebases, dcommits and tags I appear to be always commiting to an SVN tag. Doing a dcommit dry run returns:

$ git svn dcommit --dry-run
Committing to http://proj.badc.rl.ac.uk/svn/badc/users/spascoe/metaconfig/tags/0.1.1 ...
diff-tree a1265119164b79cfb12d28a7059d453fb4eb13f7~1 a1265119164b79cfb12d28a7059d453fb4eb13f7

My .git/config is:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    autocrlf = false
[svn-remote "svn"]
    url = http://proj.badc.rl.ac.uk/svn/badc
    fetch = users/spascoe/metaconfig/trunk:refs/remotes/trunk
    branches = users/spascoe/metaconfig/branches/*:refs/remotes/*
    tags = users/spascoe/metaconfig/tags/*:refs/remotes/tags/*

Poking around in .git isn't helping. Any idea what's going wrong?

A: 

The git svn command had a bug where the master branch could be left pointing to something other than svn trunk when initially importing an svn repository. It was fixed in git v1.6.5 and later (in v1.6.5-rc0~75 if you have git checked out).

If you've already finished checking out the svn repository and want to make sure the master branch points to svn trunk, do the following.

NOTE: These instructions assume that you've committed or stashed any local changes you've made. Use git stash save to save any uncommitted work and git branch newbranchname to create a branch to your last commit.

  1. Switch to the master branch using git checkout master if you're not already there. Use git branch to see your current branch, which is the one with an asterisk ('*') next to it.

  2. Run git svn info and check the "URL:" field. If the URL points to trunk, then you're done. The next git svn dcommit will commit to trunk from the master branch.

  3. If git svn info points to a tag or a branch URL, run git log and find the first commit that has a "git-svn-id:" URL that points to your svn trunk URL. Copy the 40-character commit hash (on the line that starts with "commit") that represents this commit.

  4. Reset your master branch to the commit hash using git reset --hard commit-hash replacing "commit-hash" with the commit hash from Step 3.

    NOTE: This step is the most dangerous one! Be sure you've saved all of your work! Make a tarball of your working directory if necessary.

  5. Run git svn info again to make sure the "URL:" field shows you're on trunk. If it does not, you copied the wrong commit hash in Step 3. Go to Step 3 and try again.

  6. Run git svn rebase to update your master branch to the latest revision on trunk in your svn repository.

Pro Tip: Experts will note that you can parse the "git-svn-id:" line at the bottom of each commit log to determine whether a particular commit is on trunk, on a tag or on a branch. Thus it's sufficient to use git log master to check whether the first commit on the master branch is pointing to the trunk URL of your svn repository.

ddkilzer