345

I have found various examples of how to revert an SVN commit like

svn merge -r [current_version]:[previous_version] [repository_url]

or

svn merge -c -[R] .

But neither of them seems to work. I tried those commands and checked the files that were changed by hand.

How do I revert a commit with revision number 1944? How do I check that the revert has been done (without looking in the actual file to the changes have been reverted)?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alex
  • 41,580
  • 88
  • 260
  • 469
  • 23
    Did you never accept an answer because none of them worked? – 2rs2ts Apr 16 '14 at 19:40
  • 4
    If you want a literal answer use "svn merge -c -1944 ." To check if it worked: "svn diff" – John Sampson Nov 14 '14 at 21:50
  • See also [Delete all traces of a SVN commit](http://stackoverflow.com/questions/5566327/delete-all-traces-of-a-svn-commit). – Vadzim Feb 29 '16 at 07:30
  • Possible duplicate of [How do I return to an older version of our code in Subversion?](http://stackoverflow.com/questions/814433/how-do-i-return-to-an-older-version-of-our-code-in-subversion) – Vadzim Nov 29 '16 at 15:01

14 Answers14

486

Both examples must work, but

svn merge -r UPREV:LOWREV . undo range

svn merge -c -REV . undoes a single revision, in your case REV would be 1944, i.e. the revision you wish to undo.

in this syntax - if current dir is WC and (as in must done after every merge) you'll commit results

Do you want to see logs?

jeducious
  • 25
  • 5
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • 10
    @dwjohnston - yes, merges **always performed in WC** and it's not server-side task – Lazy Badger Mar 06 '14 at 02:29
  • 14
    `svn: Merge source required`. No dice. – 2rs2ts Apr 16 '14 at 19:46
  • 27
    @2rs2ts looks like you forgot the trailing dot to designate 'do this in the current directory'. – Dalin Apr 28 '14 at 17:09
  • 18
    you can also do multiple single commits at the same time: `svn merge -c -42587,-42589 .` – mlathe Nov 07 '14 at 18:57
  • 1
    @ahnbizcad - revision (single), which you want to undo – Lazy Badger Feb 11 '16 at 06:22
  • 2
    For the second one, if it doesn't work you probably forgot the - (hyphen) before the revision number. – Mark Apr 28 '17 at 09:50
  • 1
    Is it normal for these two commands to cause a merge conflict? E.g if you have commited 1 then commited 2 then commited 3 then commited 4 then commited. And then, say each had revision number respectively 1,2,3,4. When you perform `svn merge -c -2` should this cause a conflict? – Mark May 21 '17 at 12:08
  • @Markku K. Not sure the easiest solution between a "one line script" and a "one page of instructions" is the later. – Olivier Sep 27 '17 at 13:41
  • @Olivier The OP specifically said that neither of those one liners worked for him, which makes me wonder why this answer got so many up votes. The question was "A and B don't work for me, how else can I do it?" And this answer says "Do A or B". I don't get it. – Markku K. Feb 20 '18 at 15:19
  • @2rs2ts - You just need the branch your in. In trunk you could do: svn merge ^/trunk -c -REV. Usually a good idea to merge from the top of the repository(not a subfolder) too. – DataDino May 25 '18 at 00:11
  • svn: E205001: Try 'svn help merge' for more information svn: E205001: Merge source required – Steven Byks Jul 23 '18 at 20:09
  • Actually do not remove the bad revisions from svn repository – MUY Belgium Oct 11 '18 at 08:26
  • In my case. `svn merge -c REV ./` did nothing. I have to do `svn merge -rLAST:PREVIOUS ./` I have svn, version 1.9.7 (r1800392) – Marco Sulla May 14 '19 at 10:08
  • I use this: svn update -rxxx – Alexei Mar 16 '23 at 07:51
142

If you're using the TortoiseSVN client, it's easily done via the Show Log dialog.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dodgy_coder
  • 12,407
  • 10
  • 54
  • 67
  • 5
    This is outdated. There no longer is a Context-Menu available for the client in the current version. – user1789573 Dec 29 '15 at 18:19
  • 23
    What? TortoiseSVN IS a context menu, plus the dialogs it spawns. What do you mean by "there no longer is a context menu"? There most certainly is! – Ben Mar 01 '16 at 19:01
  • @Ben I think user1789573 was getting a bit tripped up over the explicit mention of "Context Menu" in the tutorial linked to in the answer. – Tom Catullo Aug 24 '16 at 19:49
  • 3
    In case you're seeing this later, it is (still) there. In the show log screen, right click the revision and there's a "Revert to This Revision" option. This is in TortoiseSVN 1.9.4 Build 27285. I just used it and can tell you it works just fine. – Bruce Van Horn Jan 18 '17 at 23:13
  • @MarkkuK. The OP doesn't specify the OS that is used and last time I checked TortoiseSVN is Windows-only. – rbaleksandar Feb 16 '18 at 09:48
  • @BruceVanHorn should I make the commit right after I have clicked "Revert to This Revision" or reverting going to apply right after accepting the "Revert to This Revision" option? – Ihor Skliar May 10 '19 at 09:19
  • The context menu doesn't have the "revert changes" option for me. – Eliezer Miron Jul 22 '19 at 23:30
  • For anyone who's not seeing the Context Menu, I had to open the Show Log dialog from my working copy, not the Repo-Browser. – WhiteAbeLincoln Jul 01 '21 at 20:47
72

svn merge -r 1944:1943 . should revert the changes of r1944 in your working copy. You can then review the changes in your working copy (with diff), but you'd need to commit in order to apply the revert into the repository.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
onon15
  • 3,620
  • 1
  • 18
  • 22
  • 4
    Does not work, requires merge source. Tried `svn merge -r 1944:1943 .` instead, but nothing has changed. – Alex Nov 11 '12 at 10:00
  • Has the repository advanced since r1944? If so, are there conflicting changes on the same lines as the changes between r1943 and r1944? – onon15 Nov 11 '12 at 10:02
  • I am at revision 1945 and there does not seem to be a conflict. Neither `svn status` nor `svn diff` gives anything. – Alex Nov 11 '12 at 10:12
  • Does `svn merge -r 1945:1943` work? Do you see an SVN error message for the merges that don't work? – onon15 Nov 11 '12 at 10:14
  • 7
    Error: `svn: Try 'svn help' for more info svn: Merge source required` – Alex Nov 11 '12 at 10:19
  • 7
    But `svn merge -r 1945:1943 .` seem to have worked. I think I understand: You need to merge the version from 'before' the 'bad' commit into your working repository. This is ok when you want to do a simple 'revert' of the previous commit. But what if you want to revert the changes made with version 1900? – Alex Nov 11 '12 at 10:22
  • Probably, a change in revision r1945 is affecting one of the lines changed in r1944. So reversing r1944 would conflict with r1945. What you can do, is branch r1944 and revert it there, then merge back (and manually fix the conflicts with r1945) – onon15 Nov 11 '12 at 10:30
  • I had a similar problem and successfully reverted to the previous revision with svn merge -r X:X-1 .. The merge command is followed by a commit and an update. Check difference between revisions with svn diff -r X:Y --summarize, which will output files diffs between X and Y. – Alexander Feb 13 '18 at 07:29
54

First, undo the changes made in revision 1944.

> svn merge -c -1944 .

Second, check what is about to be commited.

> svn status

Third, commit version 1945.

> svn commit -m "Fix bad commit."

Fourth, look at the new log.

> svn log -l 4

------------------------------------------------------------------------
1945 | myname | 2015-04-20 19:20:51 -0700 (Mon, 20 Apr 2015) | 1 line

Fix bad commit.
------------------------------------------------------------------------
1944 | myname | 2015-04-20 19:09:58 -0700 (Mon, 20 Apr 2015) | 1 line

This is the bad commit that I made.
------------------------------------------------------------------------
1943 | myname | 2015-04-20 18:36:45 -0700 (Mon, 20 Apr 2015) | 1 line

This was a good commit.
------------------------------------------------------------------------
Antti Kissaniemi
  • 18,944
  • 13
  • 54
  • 47
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
28

It is impossible to "uncommit" a revision, but you can revert your working copy to version 1943 and commit that as version 1945. The versions 1943 and 1945 will be identical, effectively reverting the changes.

Jakub Zaverka
  • 8,816
  • 3
  • 32
  • 48
  • 19
    Just to be annoyingly accurate, I would comment that if you have admin access to the repository, you can "uncommit". This by creating a clone repository up to a given revision using `svn dump` and then `svn load`. But, of course, this shouldn't be used in normal circumstances. – onon15 Nov 11 '12 at 10:06
  • 4
    I do not want to uncommit, I want to create a new commit number with a certain commit inversed. Sets say I have checked out version 1944, made a commit in 1945, which I want to 'revert'. Then I want to have a version 1946, whose files are identical to the ones in version 1944. (Except the history of course.) But the question remains: How to do that? What are the commands? – Alex Nov 11 '12 at 10:11
  • 1
    // , @Alex, I am interested in this, too, especially in something analogous to `$ git revert`. I've found it somewhat difficult to learn SVN after using Git for so long. – Nathan Basanese Feb 06 '17 at 20:30
10

The following will do a dry run, as it says. HEAD being current version, PREV is previous, then the path to your file, or committed item:

svn merge --dry-run -rHEAD:PREV https://example.com/svn/myproject/trunk

If the dry run looks good, run the command without the --dry-run

Verify the change in revision and re-commit. To browse for version numbers try:

svn log
BentheFolker
  • 301
  • 3
  • 5
5
F=code.c
REV=123
svn diff -c $REV $F | patch -R -p0 \
    && svn commit -m "undid rev $REV" $F
jmullee
  • 390
  • 3
  • 6
2

Alex, try this: svn merge [WorkingFolderPath] -r 1944:1943

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
Nikita
  • 422
  • 5
  • 14
2

While the suggestions given already may work for some people, it does not work for my case. When performing the merge, users at rev 1443 who update to rev 1445, still sync all files changed in 1444 even though they are equal to 1443 from the merge. I needed end users to not see the update at all.

If you want to completely hide the commit it is possible by creating a new branch at correct revision and then swapping the branches. The only thing is you need to remove and re add all locks.

copy -r 1443 file:///<your_branch> file:///<your_branch_at_correct_rev>
svn move file:///<your_branch> file:///<backup_branch>
svn move file:///<your_branch_at_correct_rev> file:///<your_branch>

This worked for me, perhaps it will be helpful to someone else out there =)

lennon310
  • 12,503
  • 11
  • 43
  • 61
droxxodia
  • 21
  • 1
2
svn merge -c -M PATH

This saved my life.

I was having the same issue, after reverting back also I was not seeing old code. After running the above command I got a clean old version code.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
amit ghosh
  • 31
  • 3
1

I tried the above, (svn merge) and you're right, it does jack. However

svn update -r <revision> <target> [-R]

seems to work, but isn't permanent (my svn is simply showing an old revision). So I had to

mv <target> <target backup>
svn update <target>
mv <target backup> <target>
svn commit -m "Reverted commit on <target>" <target>

In my particular case my target is interfaces/AngelInterface.php. I made changes to the file, committed them, updated the build computer ran the phpdoc compiler and found my changes were a waste of time. svn log interfaces/AngelInterface.php shows my change as r22060 and the previous commit on that file was r22059. So I can svn update -r 22059 interfaces/AngelInterface.php and I end up with code as it was in -r22059 again. Then :-

mv interfaces/AngelInterface.php interfaces/AngelInterface.php~
svn update interfaces/AngelInterface.php
mv interfaces/AngelInterface.php~ interfaces/AngelInterface.php
svn commit -m "reverted -r22060" interfaces/AngelInterface.php

Alternatively I could do the same thing on a directory, by specifying . -R in place of interfaces/AngelInterface.php in all the above.

sibaz
  • 1,242
  • 14
  • 26
  • 1
    One other thing, as was already said, what you can't do is remove the commit from history, like you can do in git by hacking the refs directly. All you can do, is use the repository to change your source to how you intend it, and commit that as a change. – sibaz Sep 05 '14 at 15:30
  • Having investigated further I can see that it is possible to remove the commit from history using svnadmin but you're strongly advised against it. See http://stackoverflow.com/questions/5566327/delete-all-traces-of-a-svn-commit – sibaz Sep 05 '14 at 15:48
1

If you want to completely remove commits from history, you can also do a dump of the repo at a specific revision, then import that dump. Specifically:

svnrdump dump -r 1:<rev> <url> > filename.dump

The svnrdump command performs the same function as svnadmin dump but works on a remote repo.

Next just import the dump file into your repo of choice. This was tested to worked well on Beanstalk.

Rob
  • 26,989
  • 16
  • 82
  • 98
redcalfee
  • 146
  • 1
  • 6
  • I have found that the `svnrdump` generates different dump than the `svnadmin dump`. I think that might lead to unexact repository move (move with changes). The noticed differences, for example, were in hashes. The `svnrdump` creates `md5`, when the `svnadmin dump` created `md5`+`sha*` or something like that. Another difference was in the dump file size which was greater in twice for the `svnadmin dump`. – Andry Nov 07 '21 at 22:24
0

Very old thread, however there is no answer for Intellij. To revert a single commit:

Go to: Subversion -> Integrate Directory...

integrate directory view

jwpol
  • 1,188
  • 10
  • 22
0

Note that the svn merge command reverts a commit in the sense of having another commit undoing your changes, but keeping your wrong commit in the history.

In the case you are a Subversion system administrator (with command line access) and you have to revert a very big mistake (for example, someone committed something that should not be committed for no reason in the world), and if you want to try to completely drop a commit at any cost, even at the risk of destroying the repo:

Step 1. Identify your repository on your server

First of all identify your repository on your server's filesystem.

Let's assume that the pathname is /repo. But it may be /home/svn/myrepo or something like that.

The filesystem structure should be something like this:

$ ls -la /repo
total 16
drwxr-xr-x.   6 svn svn   86 10 feb  2020 .
drwxrwx---. 145 svn svn 4096 22 giu 16.14 ..
drwxr-xr-x.   2 svn svn   54 10 feb  2020 conf
drwxr-sr-x.   6 svn svn  253 17 giu 11.25 db
-r--r--r--.   1 svn svn    2 10 feb  2020 format
drwxr-xr-x.   3 svn svn 4096 10 feb  2020 hooks
drwxr-xr-x.   2 svn svn   41 10 feb  2020 locks
-rw-r--r--.   1 svn svn  229 10 feb  2020 README.txt

Let's also assume that your user is called svn like in the above example.

NOTE: if you don't know what this is talking about, you probably have not your own Subversion server and this answer may be not useful for your case. Please try other answers (where you just need to have the URL of the server, without physical access).

Step 2. Export your good history

Let's assume that your wrong revision is 100 and your correct version is 99:

svnadmin dump -r 1:99 /repo > export.dump

Step 3. Backup and re-init your repository

Create a backup of your repository and initialize it again:

mv              /repo /repo.bak
mkdir           /repo
svnadmin create /repo

Step 4. Import your good history again

svnadmin load /repo < export.dump

Now, make sure to fix your permissions with the right user:

chown -R svn:svn /repo

Is everything working? That's all! Good for you!

BUT at this point there are interesting chances you have destroyed your whole repository. For example, you may no longer be able to checkout, or, your Subversion web application (Phabricator?) may scream with weird error messages, or, you could have killed a thousand kittens by mistake in the process.

If something goes wrong stay ready with your disaster recovery:

Disaster recovery

If a disaster happen:

mv /repo     /repo.fail
mv /repo.bak /repo

Hoping to be useful.

Valerio Bozz
  • 1,176
  • 16
  • 32