0

I'm using SVN and I have a branch which was created a week ago from the trunk, I am having problems with some of the files I've changed, I used meld to check for differences, however now I'm in the situation where SVN doesn't pick up the changes because I've updated using meld...

I want to roll back the changes I've done, using svn log I can see there are commits that I want to revert back to, but I don't know how. I also want to update my branch to the trunk to ensure it is up to date before applying my changes, I've used git before and svn a long time ago, I need help with svn.

I'm using the command line in a linux (Fedora) VM, can anyone help?

SPlatten
  • 5,334
  • 11
  • 57
  • 128
  • Did you come up with a solution for your problem? If not, please share the output of `svn status` and more information on your repository and working copy layouts. Thank you. – Friedrich Jun 12 '23 at 11:18

1 Answers1

0

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"
Friedrich
  • 2,011
  • 2
  • 17
  • 19
  • Thank you, I've copied all my files that have been modified within the last 7 days to another folder, I want to update the branch from the trunk to ensure it is up to date, how can I do that? – SPlatten Jun 07 '23 at 08:17
  • BY THE WAY, my changes are already committed, I want to roll back to earlier committed versions. – SPlatten Jun 07 '23 at 08:21
  • Tried "svn merge ^/trunk .", get: svn: E195020: Cannot merge into mixed-revision working copy [43719:43868]; try updating first" – SPlatten Jun 07 '23 at 08:29
  • That's a different problem. Means you have different files (or trees) on different branches. Try `svn switch ^/branches/MYBRANCH` in the working copy's root, first. Then clean up your working copy and attempt to merge. – Friedrich Jun 07 '23 at 08:31