svn: merging branches
I'm a bit unclear about merging branches in SVN and was wondering if someone could explain...
project1
trunk
foo.c
bar.c
baz.c
branches
tags
project2
trunk
foo.c
quux.c
boing.c
branches
project1-offshoot
foo.c
bar.c
baz.c
boing.c
tags
Suppose we have the following situation. There's a "project1" in our svn repository. Bob starts a new project "project2" and starts working under the trunk. Then Charlie says "Wait a minute! That's sort of like project1!" so he tells Bob he'll create a branch for project2 called "project1-offshoot" (svn copy
from project1/trunk) and modify it appropriately to get ready for merging with project2.
What's the appropriate action for Bob and Charlie to take to merge project2/branches/project1-offshoot into project2/trunk?
Files "foo.c" and "boing.c" each have two independent histories (foo from project1/trunk -> project2/branches/project1-offshoot as well as from project2/trunk; boing from proj开发者_开发百科ect2/trunk and from project2/branches/project1-offshoot). Can a file in SVN have two ancestors? Or are you forced to choose one as the ancestor, and then do a textual merge from another file without maintaining any link to the source of that file?
You will probably need to use the merge
command with the --ignore-ancestry
option because the source files have independent histories with no shared ancestor.
From Version Control with Subversion (for Subversion 1.5), by Ben Collins-Sussman, Brian W. Fitpatrick, and C. Michael Pilato:
"Most merges involve comparing trees that are ancestrally related to one another; therefore, svn merge defaults to this behavior. Occasionally, however, you may want the merge command to compare two unrelated trees."
"If you ask svn merge to compare the two trees, you'd see the entire first tree being deleted, followed by an add of the entire second tree! In these situations, you'll want svn merge to do a path-based comparison only, ignoring any relations between files and directories. Add the --ignore-ancestry option to your merge command, and it will behave just like svn diff. (And conversely, the --notice-ancestry option will cause svn diff to behave like the svn merge command.)"
If I understand your second question correctly (i.e. "Can a file in SVN have two ancestors?") the answer is no. You'll either have to merge the changes from project1 into project 2 or vice versa.
Just a note: Usually the branches folder of a project is reserved for branches of that specific project's trunk, meaning only branches of project1's trunk goes in project1's branches folder. There's of course nothing stopping anyone from doing something different, but it does keep things nice and clean
精彩评论