Subversion: How to merge only specific revisions into trunk when multiple consecutive changes are made in a branch?

前端 未结 8 1832
孤街浪徒
孤街浪徒 2020-12-09 10:34

I have been using TortoiseSVN, svn, and subclipse and I think I understand the basics, but there\'s one thing that\'s been bugging me for a while: Merging introduces unwante

相关标签:
8条回答
  • 2020-12-09 10:41

    If you don't want the unwanted change, do not merge revision 4:5, but just revision 5. It means you merge the change committed in revision 5.

    0 讨论(0)
  • 2020-12-09 10:50

    The problem is that both svn

    A
    <<<<<<< .working
    =======
    B (unwanted change)
    C (important bug fix)
    >>>>>>> .merge-right.r341
    

    and TortoiseSVN is treating the situation as 2-way merge. I've heard of the term 3-way merge, so I gave Beyond Compare a shot. With quick set up with TortoiseSVN, Edit Conflict now bring up the following screen. This is not perfect, since it's still requiring human intervention, but at least I can tell which changes are coming from where.

    See screenshot.

    0 讨论(0)
  • 2020-12-09 10:50

    I believe you are including the revisions you want correctly, but the merge algorithm is failing to find the place to insert the wanted change and so including the line above it also. Here are the same steps but with a different set of changes, and I believe it works as you expected originally:

    $ svnadmin create repo
    $ svn mkdir -m '' file://`pwd`/repo/trunk
    
    Committed revision 1.
    $ svn mkdir -m '' file://`pwd`/repo/branches
    
    Committed revision 2.
    $ svn co file://`pwd`/repo/trunk co.trunk
    Checked out revision 2.
    $ cat > co.trunk/test.txt << EOF
    > A
    > B
    > C
    > EOF
    $ svn add co.trunk/test.txt
    A         co.trunk/test.txt
    $ svn commit -m '' co.trunk
    Adding         co.trunk/test.txt
    Transmitting file data .
    Committed revision 3.
    $ svn copy -m '' file://`pwd`/repo/trunk file://`pwd`/repo/branches/testbr
    
    Committed revision 4.
    $ svn co file://`pwd`/repo/branches/testbr co.testbr
    A    co.testbr/test.txt
    Checked out revision 4.
    $ cat > co.testbr/test.txt << EOF
    > A
    > A1 unwanted
    > B
    > C
    > EOF
    $ svn commit -m '' co.testbr
    Sending        co.testbr/test.txt
    Transmitting file data .
    Committed revision 5.
    $ cat > co.testbr/test.txt << EOF
    > A
    > A1 unwanted
    > B
    > B1 wanted
    > C
    > EOF
    $ svn commit -m '' co.testbr
    Sending        co.testbr/test.txt
    Transmitting file data .
    Committed revision 6.
    $ svn merge -r 5:6 file://`pwd`/repo/branches/testbr co.trunk
    --- Merging r6 into 'co.trunk':
    U    co.trunk/test.txt
    $ cat co.trunk/test.txt
    A
    B
    B1 wanted
    C
    
    0 讨论(0)
  • 2020-12-09 10:56

    Merging only revisions 4,7, and 11-15 with svnmerge:

    svnmerge.py merge -r4,7,11-15
    

    And with regular svn:

    svn merge -c4,7 -r10:15 http://.../branches/TRY-XX-Foo
    
    0 讨论(0)
  • 2020-12-09 10:59

    In TortoiseSVN, you must only specify the revisions you want to merge. Unlike the command line client where you have to specify e.g. -r4:5 to merge the changes between r4 and r5, you only have to specify '5' as the revision number to merge in the TortoiseSVN merge dialog. If you're not sure, always use log dialog from the merge dialog and select the revisions you want to merge in that log dialog (then click OK and the selected revisions will automatically get set in the merge dialog).

    As for resolving your conflict in TortoiseMerge: According to the screenshot in your question, TortoiseMerge shows you two conflicted lines (the ones shown as '????' in the bottom view). What you want is to include the change 'C' but not 'B'?

    • left click on the first '???' line to select it, then right-click, choose 'use block from "mine"' from the context menu
    • left click on the second '???' line to select it, then right-click, choose 'use block from "theirs"' from the context menu
    • Click the save button (or File->Save)
    • Optionally click on the "Mark as resolved" button
    0 讨论(0)
  • 2020-12-09 11:01

    Another thing you could do would be to manually undo the bad commit on the branch, which would then allow you to merge the branch back into the trunk as you would normally.

    TortoiseSVN

    Using TortoiseSVN you open up the log view on a file, select the offending version, and choose "Revert changes from this revision" from the right click menu. Commit the changes it makes on your working copy and then you can merge the branch back in easily.

    Command Line

    To do this with the command line client you perform a reverse merge, (This is taken from the Pragmatic Source Control using Subversion book) where you merge the changes between the offending version and the previous version into the working copy of the file. Then as above you'd commit the changes and can then branch normally. In your example you would do something like:

    svn merge -r 4:3 test.txt
    
    0 讨论(0)
提交回复
热议问题