How can I remove all my changes in my SVN working directory?

Svn

Svn Problem Overview


I have an SVN working directory. I made some changes in that directory, and it shows in svn status. But is there any way for me to remove all my changes in there and just get everything from the trunk using the command line?

Svn Solutions


Solution 1 - Svn

svn revert -R .
svn up

This will recursively revert the current directory and everything under it and then update to the latest version.

Solution 2 - Svn

I used a combination of other peoples' answers to come up with this solution:

Revert normal local SVN changes

svn revert -R .
Remove any other change and supports removing files/folders with spaces, etc.
svn status --no-ignore | grep -E '(^\?)|(^\I)' | sed -e 's/^. *//' | sed -e 's/\(.*\)/"\1"/' | xargs rm -rf

Don't forget to get the latest files from SVN

svn update --force

Solution 3 - Svn

svn revert -R .
svn cleanup . --remove-unversioned

Solution 4 - Svn

If you have no changes, you can always be really thorough and/or lazy and do...

rm -rf *
svn update

But, no really, do not do that unless you are really sure that the nuke-from-space option is what you want!! This has the advantage of also nuking all build cruft, temporary files, and things that SVN ignores.

The more correct solution is to use the revert command:

svn revert -R .

The -R causes subversion to recurse and revert everything in and below the current working directory.

Solution 5 - Svn

None of the answers here were quite what I wanted. Here's what I came up with:

# Recursively revert any locally-changed files
svn revert -R .

# Delete any other files in the sandbox (including ignored files),
# being careful to handle files with spaces in the name
svn status --no-ignore | grep '^\?' | \
    perl -ne 'print "$1\n" if $_ =~ /^\S+\s+(.*)$/' | \
    tr '\n' '\0' | xargs -0 rm -rf

Tested on Linux; may work in Cygwin, but relies on (I believe) a GNU-specific extension which allows xargs to split based on '\0' instead of whitespace.

The advantage to the above command is that it does not require any network activity to reset the sandbox. You get exactly what you had before, and you lose all your changes. (disclaimer before someone blames me for this code destroying their work) ;-)

I use this script on a continuous integration system where I want to make sure a clean build is performed after running some tests.

Edit: I'm not sure this works with all versions of Subversion. It's not clear if the svn status command is always formatted consistently. Use at your own risk, as with any command that uses such a blanket rm command.

Solution 6 - Svn

svn revert will undo any local changes you've made

Solution 7 - Svn

You can use the following command to revert all local changes:

svn st -q | awk '{print $2;}' | xargs svn revert

Solution 8 - Svn

svn status | grep '^M' | sed -e 's/^.//' | xargs rm

svn update

Will remove any file which has been modified. I seem to remember having trouble with revert when files and directories may have been added.

Solution 9 - Svn

Solution 10 - Svn

If you are on windows, the following for loop will revert all uncommitted changes made to your workspace:

for /F "tokens=1,*" %%d in ('svn st') do (
  svn revert "%%e"
)

If you want to remove all uncommitted changes and all unversioned objects, it will require 2 loops:

for /F "tokens=1,*" %%d in ('svn st') do (
  svn revert "%%e"
)
for /F "tokens=1,*" %%d in ('svn st') do (
  svn rm --force "%%e"
)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionn179911View Question on Stackoverflow
Solution 1 - SvnMike McQuaidView Answer on Stackoverflow
Solution 2 - SvnShaizeView Answer on Stackoverflow
Solution 3 - Svnlexa-bView Answer on Stackoverflow
Solution 4 - SvnbbumView Answer on Stackoverflow
Solution 5 - SvnmpontilloView Answer on Stackoverflow
Solution 6 - SvnSeanView Answer on Stackoverflow
Solution 7 - SvnNaNView Answer on Stackoverflow
Solution 8 - SvnJuanView Answer on Stackoverflow
Solution 9 - SvnNick Van BruntView Answer on Stackoverflow
Solution 10 - SvnDavidView Answer on Stackoverflow