How do I return to an older version of our code in Subversion?

I’m working on a project with a friend and I want to return to an older version of our code and set it to be the current. How do I do it?

I’m using “anksvn” on vs08.

I have the version that I want on my PC, but the commit is failing; The message that I get is
“commit is failed, file or directory is out of date.”

I also have the subversion client on my PC.

  • Error in jenkins during sonar analysis caused by svn blame
  • Python SVN bindings for Windows
  • Where is the 'Revert' option in Xcode 4's Source Control?
  • How can I store the new SVN revision number in my source code after I commit? (TortoiseSVN)
  • Shelve in TortoiseSVN?
  • ASP.NET Display SVN Revision Number
  • 12 Solutions collect form web for “How do I return to an older version of our code in Subversion?”

    Basically you need to “merge backwards” – apply a diff between the current and previous version to the current version (so you end up with a working copy looking like the old version) and then commit again. So for example to go from revision 150 (current) back to revision 140:

    svn update
    svn merge -r 150:140 .
    svn commit -m "Rolled back to r140"
    

    The Subversion Red Book has a good section about this.

    The reason you can’t do anything directly with the good copy you have on your PC, is that its .svn folders know that it is code from the past, so requires an update. But you can only actually commit changes at the head of the subversion history.

    You can use

    svn update -r <earlier_revision_number>

    to check various older versions of your project, until you find the right revision number, of your good version. When you have found it, update to the newest (head) revision, then apply the svn merge as suggested above.

    If you really can’t find it, and need to commit the copy on your PC, then get a fresh update to the latest version, and copy your “good” version over the top of it (without the .svn folders!). Delete any files that weren’t in the good copy from the folders and from subversion, and commit what you have now.

    The standard way of using merge to undo the entire check-in works great, if that’s what you want to do. Sometimes, though, all you want to do is revert a single file. There’s no legitimate way to do that, but there is a hack:

    1. Find the version that you want using svn log.
    2. Use svn’s export subcommand:

      svn export http://url-to-your-file@123 /tmp/filename

    (Where 123 is the revision number for a good version of the file.) Then either move or copy that single file to overwrite the old one. Check in the modified file and you are done.

    just use this line

    svn update -r yourOldRevesion

    you can know your current revision by using

    svn info

    A bit more old-school

    svn diff -r 150:140 > ../r140.patch
    patch -p0 < ../r140.patch
    

    then the usual

    svn diff
    svn commit
    

    Right-click on the highest hierarchy you want to revert >> Revert or Revert to Revision

    I think this is most suited:

    Do the merging backward, for instance, if the committed code contains the revision from
    rev 5612 to 5616, just merge it backwards. It works in my end.

    For instance:

    svn merge -r 5616:5612 https://<your_svn_repository>/
    

    It would contain a merged code back to former revision, then you could commit it.

    This is what I did and worked for me.

    I want to undo the changes in multiple commits that I did for certain times and want to go to the previous commit point.

    1. Go to Team -> Show History.
    2. Right-click on the or range of revisions you want to ignore.
    3. Select the “Revert changes” option.

    This will run a reverse merge, undoing the changes in your working copy.

    Just review the code and commit.

    Right click the project > Replace With > Revision or URL > Select the specific revision you want to revert.

    Now commit the local update code version to the repository. This will revert the code base to the specific revision.

    Sync to the older version and commit it. This should do the trick.

    Here’s also an explanation of undoing changes.

    Most of the previous answers have been using a reverse merge, and that’s usually the right answer. However, there’s one situation (which just happened to me) where it’s not.

    I accidentally changed a file with Unix line endings to DOS line endings when making a small change, and committed it. This is easily undone, either by changing the line endings and committing again, or by a reverse merge, but it has the effect of making svn blame list my edit as the source of every line of the file. (Interestingly, TortoiseSVN on Windows doesn’t get affected by this; only the command line svn blame.)

    If you want to maintain the history as reported by svn blame, I think you need to do the following:

    • Delete the file and commit.
    • In the repository, copy the previous good copy of the file into the head, and commit.
    • Restore any edits that you do want to keep.

    The deletion is a little scary, but remember you always have the file saved in the repository, so restoring it is not a big deal. Here’s some code to illustrate the steps. Assume that xxx is the revision number of the last good copy.

    svn rm svn+ssh://path/to/file
    svn copy svn+ssh://path/to/file@xxx svn+ssh://path/to -m"Restore good copy"
    svn update
    <restore the edits>
    svn commit -m"Restore edits"
    

    Note that for a copy in the repository, the destination needs to be a directory, not a filename.

    This has worked for me.
    I had a lot of local changes and needed to discard those in the local copy and checkout the last stable version in SVN.

    1 checks the status of all files including the ignored files

    2 grep all the lines to get the newly added and ignored files.

    3 replace those with //

    4 and rm -rf all the lines.

    svn status --no-ignore | grep '^[?I]' | sed "s/^[?I] //" | xargs -I{} rm -rf "{}"

    Hope this helps.

    Git Baby is a git and github fan, let's start git clone.