Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVN: Must be ancestrally related

I am getting the error message above when I use the second SVN merge option i.e. "Reintegrate a branch/automatic merge". I understand why I get the error i.e. it is because when creating the branch I simply dragged and dropped the project into a new branch from the Trunk (using Repo-Browser) instead of one of the following techniques:

  1. Use Copy To option in Repo-Browser
  2. Use Branch/Tag option (right click on project in Windows Explorer and select TortoiseSVN/Branch/Tag)

I have three questions:

  1. Why do the projects have to be ancestrally related? This question suggests that SVN simply does a file comparison if this option is selected: What are the differences between merging a range of revisions vs. reintegrate in SVN?.
  2. Do both options above make the project ancestrally related?
  3. Does a simple drag and drop of the project from Trunk to Branch make the project none ancestrally related?
like image 806
w0051977 Avatar asked Dec 09 '22 13:12

w0051977


1 Answers

Why do the projects have to be ancestrally related? This question suggests that SVN simply does a file comparison if this option is selected: SVN Merge a range of revisions vs. reintegrate.

Merging isn't merely copying file changes from one branch to another, it is a comparison of the last common ancestor with the two files being merged. This is a three way merge.

Let's say you had a file on trunk:

Line #1
Line #2
Line #3
Line #4

You make a branch of this file.

On the branch, you change line #4 as:

Line #1
Line #2
Line #3
Line #4 FOO FOO FOO

On the trunk, you change Line #3 as

Line #1
Line #2
Line #3 BAR BAR BAR
Line #4

Subversion compares the last common ancestor (the file version before any changes) with the file versions you are merging. If I'm merging the trunk to the branch, Subversion sees that I changed Line #3 on trunk, but not Line #4. Therefore, the change in Line #3 needs to be brought over, but the difference in Line #4 is the result of a change on the branch, and I shouldn't copy over Line #4 from the trunk

The merged file looks like this:

Line #1
Line #2
Line #3 BAR BAR BAR
Line #4 FOO FOO FOO

Subversion also takes into account previously merged changes, and changes you want to skip. It's actually a pretty good merge facility unless you start renaming files and moving them around wholesale. (This is suppose to be corrected in Subversion 1.9).

So, in order for a merge to work, the two files must share a common ancestor that can be used as a base for the merge. Without it, Subversion won't be able to tell what lines of a file were changed on the trunk vs. what was changed on the branch. Otherwise, it's just copying over the files from one branch to another.

You can try the --ignore-ancestry parameter. That causes Subversion to treat the merge as a diff.

Do both options above make the project ancestrally related?

Neither option (I'm taking it you're thinking of --reintegrate vs. without this option) make the project ancestrally related. That comes from making the branch via the svn cp. The --reintegrate vs. w/o reintegrate has to do with the way the merge must happen. When you merge from your base stream (usually trunk) to your branched stream, you are merging the changes that took place on your base stream onto the branched stream. This creates new revisions. When you merge back, Subversion sees the new revisions, and wants to merge those revisions back into your base stream, The reintegrate option removes this from happening.

And, when you reintegrate, you create a new version on your base stream which is why you're not suppose to merge from your branched stream back to your base stream once you use --reintegrate. You can overcome this by doing a --record-only merge from your branch stream to your base stream right after --reintegrate.

Does a simple drag and drop of the project from Trunk to Branch make the project none ancestrally related?

Depends upon the Subversion client. Some GUI Subversion clients understand a drag and drop as a svn cp and not a mere copying of the files to another directory. However, TortoiseSVN works through Windows Explorer, so a drag and drop by default is a file system copy. There is an option when you right click on a drag and drop to do a svn cp instead of a Windows File System copy.

like image 96
David W. Avatar answered Dec 11 '22 10:12

David W.