Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to discard local changes in an SVN checkout?

Tags:

svn

People also ask

Does svn update remove local changes?

The svn update command never discards or removes local changes made in your working copy.

What is svn Revert command?

Reverts any local changes to a file or directory and resolves any conflicted states. svn revert will revert not only the contents of an item in your working copy, but also any property changes.

How do I view local changes in svn?

To get an overview of your changes, use the svn status command. You may use svn status more than any other Subversion command. If you run svn status at the top of your working copy with no arguments, it detects all file and tree changes you've made.

How do I revert a directory in svn?

To revert single change (e.g. made in revision 666): cd folder svn merge -c -666 . To revert local changes (not committed yet): cd folder svn revert -R .


Just use the svn revert command, for example:

svn revert some_file.php

It is (as every other svn command) well documented in the svnbook resource or man page, or even with the svn help command.


You need to revert all the changes using the svn revert command:

  • Revert changes to a file: svn revert foo.c
  • Revert a whole directory of files: svn revert --recursive .

To discard local changes in one particular file:

$ svn revert example_directory/example_file.txt

To discard local changes in one particular folder:

$ svn revert -R example_directory/

Simple svn revert was enough for the original poster. However, a simple svn revert will not do in the more general case where you

  1. have both edits that you want to share and edits that are you do not want to share in the same file,
  2. have local changes that you are still interested in keeping for your own private benefit.

@ErichBSchulz's suggestion of using git add -p is very reasonable and much more generally applicable in such a case. The answer was just lacking some details. Assuming your current directory is the directory you want to make the sharable patch, you could do something like this:

  1. Checkout pristine version from subversion to a different directory (choose a directory name that does not exist, here using subdirectory TMP/).

    $ url=$(svn info . | awk '/^URL/ {print $2}')
    $ svn checkout "$url" TMP
    
  2. Using that pristine svn checkout as a basis, init a git repository, ignoring .svn directories; commit everything in svn head to your temporary git repository

    $ cd TMP                                                     
    $ git init && echo ".svn/" > .gitignore
    $ git add -A && git commit
    $ cd ..
    
  3. Copy the newly prepared git repository meta data to your original working directory; as the pristine subversion checkout directory is not needed, you can get rid of it. Your working directory is now both git and subversion repository:

    $ mv TMP/.git .
    $ rm -rf TMP/
    
  4. You can now use powerful and convenient git add -p to interactively choose exactly what you want to share, and commit them to your git repository. If you need to add files to the commit, do also git add <file-to-add> before git commit

    $ git add -p                            
    <interactively select (and edit) the chunks you want to share>
    $ git add ${the_list_of_files_not_in_yet_in_svn_you_want_to_add}
    $ git commit
    
  5. Using the commit, prepare a patch that you want to share. For this purpose, you could also use git diff HEAD^..HEAD, or git format-patch (the latter can be used to directly prepare emails to be sent containing the patch or multiple patches):

    $ git show -p HEAD > my-mighty-patch.patch
    

To get rid of git meta data, just do rm -rf .git/. If you plan to continue hacking with the original working directory, you could continue using git to manage your local changes. In this case you would probably benefit from the investment of learning how to use git svn.

Note: If you are familiar with git this is rather trivial thing to improvise. Otherwise this looks maybe a bit messy. You could generalize the approach by writing a script out of these steps to implement a "interactive commit" or "interactive patch creation" for svn that could be used without any understanding of git.


You could use

 svn diff important/file1.c important/file2.c > $HOME/os/firstdiff.diff

When publishing your diff, don't forget to tell the revision against which you are diff-ing.

As others replied, you could also use svn revert carefully. It depends if you want to keep your local changes for your future work or not...


Go to the root of that repository and run the following command

svn revert --depth=infinity .