简体   繁体   中英

SVN Merge - Merging back to trunk when branch doesn't share common ancestry

I need to merge back to trunk a branch branchA that was erroneously created with svn mkdir instead of svn copy .

Using svn merge --ignore-ancestry ^/branches/branchA . results in many tree conflicts, which I can only resolve by svn resolve --accept working , although what I need, is to accept the changes from branchA . I want to to that, as branchA is a superset of trunk and there hasn't been any commit to trunk in parallel to the commits in branchA .

Is there any way I can do that?

Note:
I don't have rights to run svn-admin .

The short answer: You can't. You can't because Subversion normally uses what's known as a three-way merge. You need the two end points (the HEAD of your branch and the HEAD of your trunk) plus, the most recent common ancestor (MRCA) as the third point in a merge.

The MRCA is used to determine what was changed on the branch and what was changed on the trunk. Let's say our file originally looked like this:

one
two
three
four
five
six

On the trunk we have:

one
FOO
three
BAR
five
FUBAR

On the branch we have:

one
two
BARFOO
four
five
six

We now want to merge our branch with the trunk. If we simply do a comparison, we see that lines two, thee, four, and six differ. However, lines two four and six were changed on the trunk. We don't want to change them to match what was on the branch. Instead, the only line that was changed on the branch was line #3. We replace line #3 from the branch onto trunk. No other lines are touched.

Now, Subversion merging is a bit more sophisticated than this, but this is the basic algorithm of a three-way merge: You compare the two HEADs you're merging with their MRCA. Without a MRCA, you can't merge -- which is the situation you're in.

Even the --ignore-ancestory flag won't work because you have foo.txt on trunk and foo.txt on your branch. They may look like the same file to you, but they're not the same file according to Subversion. They are two completely different files that just happen to be located in the same directory and have the same name.

If you want to simply force your trunk to look like your branch, you can try the --accept theirs-full flag. Again, I'm not 100% sure this will work because Subversion may refuse to recognize the file names. If you don't have Subversion 1.8 installed, you can try the --reintegrate option.

Finally, you can try to fool Subversion. Make another branch at the correct branching point from trunk. Check out that new branch. Copy your files from the bad branch to this new branch using your system's copy command (and not through Subversion). Now, commit any changes (you might have to add in non-existent file and delete the ones that should no longer exist). Commit the change.

You should have a new branch that looks exactly the same as the bad branch. However, since this branch has a MRCA, you should be able to do a merge.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM