Subversion / How to use svn merge
From WhyNotWiki
Synchronization with Subversion edit (Category edit)
Merging is essentially synchronization between branches within a single repository.
svn merge lets you take the differences between 2 trees (or files) and apply them to another tree (or file). This is useful for rolling back a change you made and for applying changes from one branch to another.
I'm not sure where they got the name "svn merge"; it would be more aptly named "svn diff-and-apply". It basically takes the results of an svn diff, makes a "patch" out of them, and applies that patch to a working copy of your choice.
[edit] It's very similar to svn diff
http://svnbook.red-bean.com/en/1.2/svn.branchmerge.copychanges.html
It's time to use the svn merge command. This command, it turns out, is a very close cousin to the svn diff command (which you read about in Chapter 3). Both commands are able to compare any two objects in the repository and describe the differences. For example, you can ask svn diff to show you the exact change made by Sally in revision 344: ... The svn merge command is almost exactly the same. Instead of printing the differences to your terminal, however, it <u>applies them directly to your working copy as ''local modifications''</u>:
[edit] How to roll back a single file to revision 10
$ cd ~/my_working_copy # Preview the changes $ svn diff -r11:10 # Notice the order of revision numbers # The lines with +s in front of them are the ones that will be added back to my working copy. # Now to *apply* this diff to my working copy, I'll use the "svn diff-and-apply" command. $ svn merge -r11:10 file.html file.html # /\ file to do the diff on # /\ file to apply the diff to U file.html # Preview again before you commit (if you want) $ svn diff # Now I just commit my local modifications back to the repository the same way I would if I'd made the modifications by hand. $ svn ci
[edit] How to roll back a whole directory tree to revision 10
Pretty much the same thing, but put the directory instead of the file.
$ svn merge -r 11:10 ./ ./
[edit] How to roll back a whole directory to revision 10 that I accidentally deleted in revision 11
I tried to do this once but could not get it to work with svn merge!
$ svn merge --force http://svn/svn/my_repos/test@11 http://svn/svn/my_repos/test@10 test svn: REPORT request failed on '/svn/my_repos/!svn/vcc/default' svn: Cannot replace a directory from within
Huh??
$ svn merge -r11:10 http://svn/svn/my_repos/test svn: REPORT request failed on '/svn/my_repos/!svn/bc/11/test'
That actually sort of makes sense: the test/ directory doesn't exist in revision 11 because it was deleted in revision 11! But how do I get around that??
$ svn merge -r11:10 http://svn/svn/my_repos/test test/ svn: The location for 'http://svn/svn/my_repos/test' for revision 10 does not exist in the repository or refers to an unrelated object
"or refers to an unrelated object" -> okay, I'll use --ignore-ancestry !
$ svn merge --ignore-ancestry -r11:10 http://svn/svn/my_repos/test test/ svn: Use --force to override this restriction svn: 'test' is not under version control
$ mkdir test $ cd test test $ svn merge --ignore-ancestry -r11:10 http://svn/svn/my_repos/test svn: '.' is not a working copy
What I ended up doing:
$ svn up -r10
$ cd test
test $ find -name ".svn*" -exec rm -r {} \;
$ cd ..
$ mv test test2
$ svn up
D test
Updated to revision 11
$ mv test2 test
$ svn add test
$ svn ci
Yuck, that's a complicated pain!
[edit] Links
http://svnbook.red-bean.com/en/1.2/svn.branchmerge.copychanges.html
http://svn.haxx.se/users/archive-2005-03/0926.shtml
Remember that 'svn merge' compares two trees, and applies the differences to a working-copy tree. That means all 3 trees need to "line up" semantically.
In your case, you should be comparing two snapshots of trunk, and applying them to a working copy of the branch. (One of your mistakes above is asking merge to compare two snapshots of *one file*. That's way too narrow a comparison, unless you're really only interested merging changes from/to exactly one file -- but that's not what you asked for.)
The syntax for merge is:
svn merge URL1@X URL2@Y working-copyor, a shorter form, if the URLs are the same:
svn merge -rX:Y URL working-copySo you're making mistakes on multiple levels. First of all, the reason nothing works until you "cd" into a directory is because you're not specifying the working copy argument -- which means it's defaulting to '.', the current working dir. (Your first merge attempt was asking svn to compare two files, and apply the differences to '.' -- that's guaranteed to make no sense. The difference between two files can only be applied to another file!)
What you want to do is
$ cd branch-working-copy $ svn merge -r437:HEAD URL-of-trunkor, if you don't want to cd into the working copy,
$ svn merge -r437:HEAD URL-of-trunk branch-working-copy
[edit] Which arguments can you omit? (or, What to do if it says "Cannot replace a directory from within")
Feel free to learn from these examples of what does and doesn't work.
Doesn't work: ~/svn/my_repos/web $ svn merge -r4739:4738 include/html/header.inc.html svn: REPORT request failed on '/svn/glass/!svn/vcc/default' svn: Cannot replace a directory from within You have to give the destination / working copy path as well because otherwise it will default to ./ (which is a directory!)! ~/svn/my_repos/web $ svn merge -r4739:4738 include/html/header.inc.html include/html/header.inc.html U include/html/header.inc.html If you cd into the right directory first, it can figure it out: ~/svn/my_repos/web/include/html $ svn merge -r4739:4738 header.inc.html U header.inc.html
[edit] Svnmerge.py
| Categories/Tags: | [Libraries for Subversion (category)][Merging (category)] |
|---|---|
| Homepage: | http://www.orcaware.com/svn/wiki/Svnmerge.py |
| Documentation: | wiki mailing list
|
| Description: | svnmerge.py is a tool for automatic branch management. It allows branch maintainers to merge changes from and to their branch very easily, and automatically records which changes were already merged. This allows displaying an always updated list of changes yet to be merged, and totally prevents merge mistakes (such as merging the same change twice).
|
http://www.orcaware.com/svn/wiki/Svnmerge.py
You can think of svnmerge as the equivalent of yellow sticky notes on a Subversion branch that record which revisions have been merged in already from one or more other branches, plus some useful functionality for viewing, managing and updating that information.
[edit] Features
- Merge tracking support: the tool remembers which revisions have been already merged, and always does the right thing by default (only merges new revisions).
- Specific support for development branches with a very simple "merge everything" command (does everything automatically).
- Specific support for release branches through cherry-picking: name and merge single revisions or revision ranges.
- List revisions available for merging (revision numbers, logs, or diffs).
- Bidirectional merges: merges changes forth and back between a branch and its head.
- Multiple heads support: merge changes from multiple sources. This is useful, for instance, for the trunk, which usually needs to merge changes from multiple branches.
- Revision blocking: mark some revisions as unwanted in the branch, so that they will never get merged and you can forget about them.
- Merge rollbacks: freely revert merges in case you changed your mind.
- Absolutely commit-free: the user will always have to do the commit by himself, and thus will always have a chance to review svnmerge.py's modifications.
- Commit message suggestions: an informative commit message listing all the logs of the merged revisions is generated in a text file, as a suggestion for a good commit message.
- Manual merges support: if you merged some changes manually, you can inform svnmerge.py to update its merge tracking info.
[edit] Quick Usage Overview
- Use svnmerge init to intialize merge tracking on a branch directory.
- Use svnmerge avail to review the revisions available for merging.
- Use svnmerge merge to merge in some or all available revisions from other branches.
- Commit the merge changes using svn commit.
- Return to step 2 and repeat.
| Description | [Oops! No type defined for attribute] |
