For subversion's merge tracking feature, it's very important to use svn merge
instead of any (non-svn) merge tool like meld. This problem illustrates this. Subversion uses its special property svn:mergeinfo
to keep track of what was merged where.
Step 0: Make sure you have a clean working copy
Subversion will refuse to merge into a mixed revision working copy. This should generally not be an issue but it turned up in a comment.
To prevent a mixed revision working copy, always call commands like svn merge
or svn switch
from the working copy's root.
To pull your working copy on one branch, go to the working copy root and do
svn switch ^/branches/MYBRANCH
Step 1: Undo local, uncommitted changes
To roll back all uncommitted changes in a file or in a directory tree use
svn revert FILENAME
svn revert --depth infinity DIRECTORY
This will undo everything you did to FILENAME
or files in DIRECTORY
since your last commit.
For mixed changes in a file, some as a result of your work and some as the result of the flawed merge using meld, you have no other option than to go through the changes line by line and remove the erroneous changes.
By the way, meld can be used for this task if you call meld .
in the working copy's root dir.
Step 2: Undo committed changes
To undo commits made in error, do a reverse-merge. See SVN reverse merge? or How do I revert an SVN commit?
You need to identify which revisions (or batch of revisions were made in error with svn log
(and possibly svn diff
and svn blame
):
svn log # identify revision X which should not have been committed
svn diff -c X # optional to verify
svn blame -c X # optional to verify
svn merge -c -X # reverse-merge revision X
svn commit -m"Undo revision X"
Step 3: Merge from trunk
Once you have your working copy on branch and cleaned up, commit your work using svn commit
. Afterwards, to merge the changes from trunk, do
svn update
svn status # make sure working copy is clean and on branch
svn merge ^/trunk . # merge all changes from trunk to here
# resolve conflicts, if any
svn commit -m"Merge changes from trunk"
This will merge the changes into your working copy. After having resolved all conflicts (if any), do an svn commit
.
Step 4: Re-apply stashed changes
To update the branch from the trunk and then add changes, go to the working copy on the branch and make sure it does not contain any changes (this is somewhat optional but you don't want to mix merges and feature code changes)
svn update
svn status # make sure working copy is clean
# copy "stashed" changes to here, review
svn commit -m"My changes from the last 7 days"