4.8. Undoing Working Changes
Suppose while viewing the output of svn diff
you determine that all the changes you made to a particular file are mistakes.
Maybe you shouldn't have changed the file at all, or perhaps it would be easier to make different changes starting from scratch.
You could edit the file again and unmake all those changes.
You could try to find a copy of how the file looked before you changed it, and then copy its contents atop your modified version.
You could attempt to apply those changes to the file again in reverse using patch -R
.
And there are probably other approaches you could take.
Fortunately in Subversion, undoing your work and starting over from scratch doesn't require such acrobatics. Just use the svn revert
command:
$ svn status README
M README
$ svn revert README
Reverted 'README'
$ svn status README
$
In this example, Subversion has reverted the file to its premodified state by overwriting it with the pristine version of the file cached in the text-base area.
But note that svn revert
can undo any scheduled operation.
For example, you might decide that you don't want to add a new file after all:
$ svn status new-file.txt
? new-file.txt
$ svn add new-file.txt
A new-file.txt
$ svn revert new-file.txt
Reverted 'new-file.txt'
$ svn status new-file.txt
? new-file.txt
$
Or perhaps you mistakenly removed a file from version control:
$ svn status README
$ svn delete README
D README
$ svn revert README
Reverted 'README'
$ svn status README
$
The svn revert
command offers salvation for imperfect people.
It can save you huge amounts of time and energy that would otherwise be spent manually unmaking changes or, worse, disposing of your working copy and checking out a fresh one just to have a clean slate to work with again.