How to merge branch back to trunk in SVN with all commit history?

后端 未结 5 571
长情又很酷
长情又很酷 2021-01-30 17:32

How to merge branch back to trunk in SVN with all commit history? I know in Git I can use

merge -squash

Is there any equivalent command in SVN?

相关标签:
5条回答
  • 2021-01-30 18:04

    To create a merge of a branch and create a single commit for each commit in the branch you can use a script, I'm using the following:

    #/bin/bash
    
    BRANCH="http://your branch url"
    
    for i in {1127..1138} # list of revisions
    do
      REV=$i
      echo $REV $BRANCH
      echo merged $REV from $BRANCH > tmps.commit
      svn log -c $REV $BRANCH >> tmps.commit
      svn up
      svn merge -c $REV $BRANCH ./
      svn commit -F tmps.commit
      rm tmps.commit
    done
    

    This will check out each revision you specify for the specific branch and perform a commit on the current directory, thus preserving each single change with the corresponding message.

    0 讨论(0)
  • 2021-01-30 18:07

    With Subversion 1.5 or later the merge is recorded on your local working copy in the svn:mergeinfo property. So this information is not lost.

    You can see the merged revisions if you use svn log -g instead of the normal svn log.

    Normal merges are performed as

    svn merge -rREV1:REV2 svn://server/branch my_trunk_wc 
    

    But if you use a branch it is sometimes more convenient to use a reintegration merge. In this case you should first merge all trunk changes to the branch using something like

    svn merge svn://server/trunk my_branch_wc
    

    (This merges everything that is not already merged)

    And after you commit this change to the branch you can use

    svn merge --reintegrate svn://server/branch my_trunk_wc
    

    To move all changes over as a single commit. (After this operation you should remove the branch)

    0 讨论(0)
  • 2021-01-30 18:12

    I'm a bit rusty with merging, but shouldn't that do the trick ?

    svn merge -rREV1:REV2 svn://server/branch my_trunk_wc
    

    See:

    svn merge --help
    
    0 讨论(0)
  • 2021-01-30 18:20

    It sounds like you want to:

    1. Merge from possibly several branches.
    2. Have all the merges properly recorded as such.
    3. Commit as one new revision only.

    I think this is supported by the underlying SVN architecture. But I don't know if there are any clients that provide it (though svnmucc will do it for multiple cp, mv, rm commands). Unless you want to do more research than I have (which would not take much), or write your own client which can drive the SVN libraries to do it (which may be hard but still doable); then I think you will have to sacrifice one of 2. and 3. above.

    (If you sacrifice 3 you could dump the repository immediately after and hack the dump file to use one revision only, but I don't think it's worth the risk just to have a minutely simpler revision history...)

    0 讨论(0)
  • 2021-01-30 18:28

    You can save each changeset as a diff and then commit each one atop the trunk. This is commonly called "transplanting", and there are various tools to do this automatically.

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