Using git-svn to merge a svn branch back into trunk and trunk back into the branch

前端 未结 5 886
北荒
北荒 2021-02-05 19:39

So I\'m using git and interacting with an svn repo.

I have a svn TRUNK that looks like this:

A-B-C-D

And a svn bug_fixes branch that br

相关标签:
5条回答
  • 2021-02-05 20:26

    Would this not be a good case for rebasing your local stuff (<branchpoint>..i) onto the new master fetched from SVN?

    0 讨论(0)
  • 2021-02-05 20:28

    Ok, so a few approaches that I found:

    git checkout your_branch
    git rebase master
    git checkout master
    git merge your_branch
    

    or

    git checkout your_branch
    git rebase master
    git checkout master
    git merge --squash your_branch
    

    or

    git checkout your_branch
    git rebase master
    git checkout master
    git rebase -i your_branch
    

    And then after all that.

    git svn dcommit (to commit to master)
    git branch -D your_branch
    

    Then (from svn because git-svn doesn't support deletion) delete the branch, and recreate it from trunk and start the cycle all over again.

    0 讨论(0)
  • 2021-02-05 20:28

    If you dcommit a merge it automatically squashes it into 1 commit. Sadly it does not internally use svn:mergeinfo or --reintegrate as it should, so you lose the association with the branch created via 'git svn branch'.

    0 讨论(0)
  • 2021-02-05 20:38

    What you also can do is cherry-pick, provided that you wouldn't use merge.

    Both statements should be done on the branch without the changes.

    Provided that c is older than i and that you want to take the whole sequence.

    git cherry-pick c..i
    

    Or separate commits

    git cherry-pick c d e f g h i
    
    0 讨论(0)
  • 2021-02-05 20:41

    The Caveats section of the git-svn documentation warns

    For the sake of simplicity and interoperating with a less-capable system (SVN), it is recommended that all git svn users clone, fetch and dcommit directly from the SVN server, and avoid all git clone/pull/merge/push operations between git repositories and branches.

    The author does provide a recommendation:

    The recommended method of exchanging code between git branches and users is git format-patch and git am, or just dcommiting to the SVN repository.

    Adapting to your situation

    git format-patch --stdout c^..i >my.patch
    git reset --hard trunk
    git am <my.patch
    

    where c and i are appropriate identifiers for the commits in your history.

    0 讨论(0)
提交回复
热议问题