svn revert from changeset
Is there a way to revert from a particular changeset?
The changes has been committed, as I see from the changeset. Now, I want to revert back the files from before they were committed.
I did svn revert path/to/file but it's not asking fo开发者_如何转开发r a password or anything. Nothing is happening.
You can do a "reverse merge" i.e. "apply" all the changes FROM your current revision TO the revision you want to go back to (i.e. undo all the changes FROM the revision you want to go back to TO the current revision).
svn merge -r HEAD:nnnn .
where nnnn
is the revision you want to go back to. http://svnbook.red-bean.com/en/1.5/svn.ref.svn.c.merge.html
After reviewing the changes, resolving any conflicts etc., use svn commit
to push the changes to the repository.
Solved: svn merge -r1234:4321 path/to/yourfile path/to/thefileyouwanttogobackto,
where
1234 is your revision
4321 is the revision you want to go back to.
The simplest way is described in the SVN Book:
$ svn merge -c -303 http://svn.example.com/repos/calc/trunk
That will undo any changes made in changeset 303 and you can review and commit them as necessary.
If you know certain revision you want to revert here is one more way to revert it.
svn diff -c r1031 | grep ^Index | awk '{ print $2}' | xargs -I {file} svn export -r 1030 {file} {file}
It finds all files changed in r1031 and replace it with the same files from revision 1030.
P.S.: Also please, be careful if files you want to revert doesn't present in 1030. It could probably work not the way you expected.
See this blog entry for details:
http://blog.mafr.de/2008/05/13/revert-a-commit-in-svn/
with some good background explanation:
To understand what’s happening here requires some background on what the merge command does conceptually: It records which changes have to be made to revision N to turn it into revision N+1 (called a delta) and applies it to the working copy. That’s not what we want in our scenario, so we reverse the usual order of revisions on the command line. Effectively, we tell the merge command to create a delta the other way round. The result is a "rewinding" of the code base.
And also, in the comments, how to do this in TortoiseSVN:
To do this with TortoiseSVN, you right-click the directory or file you’d like to revert and use “Merge” from the TortoiseSVN menu. Select the option “Merge two different trees”. Under “From” select the Head revision. Under “To” select the old revision + 1 (i.e. if you’d like to revert to revision 169, type revision 170 into the box).
精彩评论