214

I was in the middle of doing a recursive svn add/commit, and a folder which did not have the proper ignore properties was included. I've got about 100 uploaded binary files versioned now, but I haven't committed yet.

What is the easiest way to 'undo' this, without deleting all the documents?

Nakilon
  • 34,866
  • 14
  • 107
  • 142
Lowgain
  • 3,254
  • 5
  • 27
  • 30

5 Answers5

250

Use svn revert --recursive folder_name


Warning

svn revert is inherently dangerous, since its entire purpose is to throw away data — namely, your uncommitted changes. Once you've reverted, Subversion provides no way to get back those uncommitted changes.

http://svnbook.red-bean.com/en/1.7/svn.ref.svn.c.revert.html

Julien Lebosquain
  • 40,639
  • 8
  • 105
  • 117
  • 12
    To expand upon this - `revert` without a revision specified undoes any changes which occurred since the last checkout, including add/delete scheduling changes, for the specified file(s). – Amber May 25 '10 at 17:32
  • where folder_name is the parent folder of the folder where you did the "Add" command – JustBeingHelpful Aug 10 '13 at 21:56
  • 33
    This answer is dangerously incorrect - it will unstage your changes BY REMOVING YOUR LOCAL COPIES OF THE FILES. Brian Lacy's answer below is much better. – Henry Henrinson May 19 '16 at 12:04
  • 6
    Guys, this answers the original question: a file or folder that was added, then reverted, only goes back to being non versioned, without being deleted. That's exactly what the question asks. If you use it on modified files, of course it reverts them: but that wasn't the question. That's even the very specific use case shown on the linked page! – Julien Lebosquain May 24 '16 at 17:08
  • 2
    @JulienLebosquain Ok, I guess you and I understand this phrase differently: *without deleting all the documents*. Unfortunately, `svn revert` does also delete the newly added *changes* in the working copy, by restoring the lastest `HEAD` version. I removed my downvote, but I still feel the warning is important. – jpaugh May 25 '16 at 17:56
  • @jpaugh if the files aren't committed there wont be any copy in the working dir to overwrite any local changes – 99 Problems - Syntax ain't one Sep 02 '16 at 13:41
164

svn rm --keep-local folder_name

Note: In svn 1.5.4 svn rm deletes unversioned files even when --keep-local is specified. See http://svn.haxx.se/users/archive-2009-11/0058.shtml for more information.

Climbs_lika_Spyder
  • 6,004
  • 3
  • 39
  • 53
Brian Lacy
  • 18,785
  • 10
  • 55
  • 73
  • 10
    This is good to know as it allows you to simply undo the "svn add" without losing changes! – Ryan H. Jan 20 '12 at 14:18
  • 1
    Are you certain SVN 1.5.4 deletes unversioned files? The report wasn't reproductible, and there's no other email about that. – Quentin Pradet Oct 17 '13 at 08:29
  • 4
    This is the better answer if you want to "unadd" the files, but still keep them. After this command, the files will still be there with the ? status. – Robin Zimmermann Oct 03 '14 at 18:46
33

Try svn revert filename for every file you don't need and haven't yet committed. Or alternatively do svn revert -R folder for the problematic folder and then re-do the operation with correct ignoring configuration.

From the documentation:

 you can undo any scheduling operations:

$ svn add mistake.txt whoops
A         mistake.txt
A         whoops
A         whoops/oopsie.c

$ svn revert mistake.txt whoops
Reverted mistake.txt
Reverted whoops
bobah
  • 18,364
  • 2
  • 37
  • 70
  • 7
    No! Revert is unsafe, as it looses all local changes – jpaugh May 24 '16 at 16:34
  • @jpaugh - This is exactly what I wrote in the answer, no? – bobah May 24 '16 at 17:37
  • 4
    What the OP asked for (and what I was expecting) was a command to undo the add *without* loosing local changes. `svn revert`. None of the answers here mention the fact that local changes will be lost by the revert. – jpaugh May 24 '16 at 18:57
5

Full process (Unix svn package):

Check files are not in SVN:

> svn st -u folder 
? folder

Add all (including ignored files):

> svn add folder
A   folder
A   folder/file1.txt
A   folder/folder2
A   folder/folder2/file2.txt
A   folder/folderToIgnore
A   folder/folderToIgnore/fileToIgnore1.txt
A   fileToIgnore2.txt

Remove "Add" Flag to All * Ignore * files:

> cd folder

> svn revert --recursive folderToIgnore
Reverted 'folderToIgnore'
Reverted 'folderToIgnore/fileToIgnore1.txt'


> svn revert fileToIgnore2.txt
Reverted 'fileToIgnore2.txt'

Edit svn ignore on folder

svn propedit svn:ignore .

Add two singles lines with just the following:

folderToIgnore
fileToIgnore2.txt

Check which files will be upload and commit:

> cd ..

> svn st -u
A   folder
A   folder/file1.txt
A   folder/folder2
A   folder/folder2/file2.txt


> svn ci -m "Commit message here"
mud1e
  • 99
  • 1
  • 4
  • 1
    Thanks, exactly what I needed. It seems it reverted only the 'add' operation, not touching the file content itself. I was scared about losing the local changes as commented on previous answers, but it seems no files were harmed. – Peter M. - stands for Monica May 22 '18 at 19:11
3

For Files - svn revert filename

For Folders - svn revert -R folder

Arvind singh
  • 1,312
  • 15
  • 15