简体   繁体   中英

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?

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'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM