svn – how to undo last commit

Often we need to undo our last commit or an old recent commit in svn. These are quick steps you can follow to undo last commit. These needs to be done in svn working directory. Also it is better you don’t have other changes in that working directory.

get last revision id in svn

First we need the revision id of the last commit. Here is how you can get it:

$ svn update
$ svn log -l 1
r3745 | user1 | 2015-11-23 03:10:50 +0000 (Mon, 23 Nov 2015) | 2 lines

blah blah bla


Ensure that the revision id is correct by reviewing the commit message.

Undo a specific revision in svn

To undo a specific revision you can use the following command:

$ svn merge -c -r3745 .

This will create the undo changes in your working copy. Now you can review these and commit:

$ svn diff
$ svn commit

In case you have other edited files in working directory, you can commit only the relevant files.

$ svn diff [relevant_files]
$ svn commit [relevant_files]

Please note that undoing actually will mean you create a new revision with the negatives changes of last commit.

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments