git-svn dcommiting a single git commit

前端 未结 4 576
感动是毒
感动是毒 2021-01-31 04:01

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 rig

4条回答
  •  生来不讨喜
    2021-01-31 04:40

    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.

提交回复
热议问题