tags:

views:

286

answers:

2

Given multiple unpushed git commits, is it possible to git-svn dcommit only one of those commits?

e.g. I have commit foo, bar, and baz, but right now I only want to have bar end up in the svn repo. Is this possible?

+2  A: 

I have one sort of crusty answer. You can create a new branch with out foo, bar, and baz in it and then cherry-pick bar to the new branch and then git-svn dcommit that branch and remove it when you're done. That doesn't seem very elegant though.

So assuming foo, bar, and baz are in branch x and master doesn't have any of them.

git branch y master

git checkout y

git cherry-pick <sha1 of bar>

git svn dcommit

git checkout x

git svn rebase

git branch -d y

If master does have these commits you can reset the head as Sizzler suggests.

docgnome
I’d dcommit the main branch and keep those other bits separate. You may be able to use the stash here, too.
Ben Stiglitz
@Ben I'm not sure how dcommiting the main branch would help. I've already got foo and bar and baz as commits in git. They just haven't made it up to the svn repo yet. If I make a new branch and cherry-pick the ones I want then I only get those commits.
docgnome
+3  A: 

git svn dcommit cannot selectively commit bar. if you have directly committed foo, bar and baz on your master branch then you have to do the following to get only bar in svn.

Assume bar's commit sha is something like 13abc...

and git log master shows all your 3 commits foo, bar and baz.

  • you need to create a branch from master

    git branch wip

the wip branch now has foo, bar and baz

  • reset the master's head to a commit before any of foo, bar or baz. you can do that using git reset (read the manual, the differences between hard,soft and mixed options affects uncommitted changes in your working tree)

    git reset --hard (COMMIT-ID before foo,bar,baz)

    (or)

    git reset --hard HEAD~3 (go back 3 revisions)

now your master branch has none of foo, bar or baz. verify with git log.

  • now you can cherry pick only the commits you want to dcommit to svn from the wip branch into master. so to get bar

    git cherry-pick wip 13abc (sha of bar commit)

the master only gets the bar commit alone.

  • now git svn dcommit should push bar alone.

Suggested Future usage

So for git-svn it is preferable not to make commits directly on master branch which is tracking remote svn. do your work on local branches and merge selectively to master before dcommiting.

Pradeep
I've heard differing opinions about where the merge should happen. The way I do it now, is branch and dcommit and then rebase master. I Keep master as the canonical tracking branch and do my work in other branches. I then push those changes up to svn and pull them down into master. That's how it was suggested I do it in #git on freenode. I was doing it the way you suggest before, but it's an extra step as you need to merge the changes into master instead of just pushing them to svn and pulling them back down with rebase.
docgnome