174

I accidentally ran svn add * and added a bunch of files that shouldn't be in the repository. I also have local edits in some files that I want to keep. Is there a simple way to just undo the svn add without reverting the local edits? The main suggestion I see on Google is svn revert, which supposedly undoes the local edits.

4 Answers 4

307

That would be:

svn rm --keep-local

The same thing happened to me. :-P

Many people have commented that you should use:

svn rm --keep-local FILENAME

to apply the command on one or many files. (The first command would apply to everything, which may have unintended side-effects.)

10
  • 1
    This had no effect for me. I ran the code as above (including the trailing period) from the base folder. Not sure if I'm missing something.
    – zzz
    Jan 20, 2012 at 0:47
  • 8
    Note thou that you have to add file name to the command so that would be svn rm --keep-local FILENAME. The FILENAME may use * to match multiple files (if you are lucky enough to have a pattern). Sep 30, 2013 at 8:21
  • 4
    warning! - using this command while using svn externals removes all the attached externals as well...
    – kostja
    Oct 9, 2013 at 14:05
  • 2
    If you commit this, won't the commit include the removal of the file in question from the repo?
    – jwg
    Apr 1, 2014 at 12:51
  • 1
    // , I have the same question as jwg. I made some edits to a SVN controlled file. I want to keep those edits locally. However, I do not want to remove the file from the repository altogether. I just don't want to push my local edits to the file. Sep 18, 2015 at 19:13
35

If those files are under a directory which has not been committed yet, you can remove the whole directory contents from the next commit by doing:

svn delete --keep-local /path/to/directory

However, if those files are already in the repository and now contain changes that you do not want to commit, you can commit the rest of the files using changelists:

svn changelist somename /file/to/be/committed
svn commit --changelist somename
8

You can fix your checkout in the following way:

  1. Backup your local files
  2. Revert the SVN checkout
  3. Restore the files

-

rsync -av --exclude .svn/ YOURDIR/ YOURDIR.bak
svn revert -R YOURDIR
rsync -av YOURDIR.bak/ YOURDIR 
2
  • The final command always creates an extra directory level, i.e. ending up with YOURDIR/YOURDIR/, although I think the issue is in the initial backup command creating YOURDIR.bak/YOURDIR/.
    – James
    Jan 1, 2018 at 19:37
  • To avoid that rsync requires a trailing slash on the source directory. I edited the answer. Jan 2, 2018 at 20:23
3

I had same problem, i accidentally add a /directory via svn add that contains the binaries and compiled file. This command actually deletes the directory.

svn rm --force <directory-name>

In my case i don't need the directory so it was safe to delete. If you want to keep the files/directories save then to a place before applying the command and after copy them back

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.