Alex
Alex

Reputation: 44395

How to revert a commit made to a particular file in SVN?

Although there have been many questions already related to svn revert, I am not sure if this particular question has been asked before. So please read on first before you close/delete/etc. this question.

In a SVN repository a change to a file has been made as part of a larger commit. This revision, lets call it 1100, has changed the content of many files, including the file in question, lets call it foo.php.

As time goes by, several other changes were made to the repository, including to file foo.php (lets say in revisions 1200, 1300, 1400 and 1500).

At a later time it was evident, that the changes made to file foo.php at revision 1100 were incorrect. But ONLY revision 1100 and ONLY the specific file foo.php.

How can I easily revert the commit 1100, without affecting any other file, and with keeping all the intermediate changes made to file foo.php in revisions 1200 through 1500?

Upvotes: 1

Views: 433

Answers (1)

kostix
kostix

Reputation: 55563

Reverting a commit in Subversion is applying a reverse patch to a file and then committing.

Suppose a file "foo.php" has a wrong change applied to it in revision N. You can see what was changed by running something like

svn diff -c N ^/path/to/that/foo.php

Now you could get the reverse diff by running

svn diff -c -N ^/path/to/that/foo.php

So to revert the change do

svn merge -c -N ^/path/to/that/foo.php

while your work tree has a sensible state, then commit.

This form of merging is called "cherry-picking", and let's cite the particular bit of svn help merge:

A 'reverse range' can be used to undo changes. For example, when source and target refer to the same branch, a previously committed revision can be 'undone'. In a reverse range, N is greater than M in '-r N:M', or the '-c' option is used with a negative number: '-c -M' is equivalent to '-r M:<M-1>'. Undoing changes like this is also known as performing a 'reverse merge'.

Upvotes: 2

Related Questions