{"id":348,"date":"2007-08-22T22:29:09","date_gmt":"2007-08-23T02:29:09","guid":{"rendered":"http:\/\/jclark.org\/weblog\/2007\/08\/22\/undoing-changes-and-new-files-with-subversion\/"},"modified":"2007-09-08T13:36:26","modified_gmt":"2007-09-08T17:36:26","slug":"undoing-changes-and-new-files-with-subversion","status":"publish","type":"post","link":"https:\/\/jclark.org\/weblog\/2007\/08\/22\/undoing-changes-and-new-files-with-subversion\/","title":{"rendered":"Undoing changes and new files with Subversion"},"content":{"rendered":"<p><strong>Update 8 Sept:<\/strong> Ryan Bates&#8217; <a href=\"http:\/\/railscasts.com\/episodes\/36\">Railscast episode #36<\/a> shows you how to setup a new rails project in Subversion, including setting up trunk\/tags\/branches, and a number of tips to make using svn with rails easier.   He doesn&#8217;t cover undoing new files, but it&#8217;s a great introduction that I wish I&#8217;d had when I started using Subversion with Rails.  Highly recommended.<\/p>\n<hr \/>\n<p>I&#8217;m new to <a href=\"http:\/\/subversion.tigris.org\/\">subversion<\/a>, so if there&#8217;s a better way to do this, please pass it along.  I just worked this out, and I&#8217;m posting here as much for my own reference as anyone else&#8217;s.<\/p>\n<p>Let&#8217;s say you&#8217;ve got made a bunch of changes in the working directory of a project managed with Subversion.  These changes include new files added to the tree, possibly in new directories\/subdirectories.  As a concrete example, suppose you&#8217;ve just run a Rails generator (e.g. <code>script\/generate resource user<\/code>), and changed your mind (e.g., you should have used <code>scaffold_resource<\/code>).  You want to revert to the last check in, reverting existing files and removing any newly created files and\/or directories that don&#8217;t exist in the repository.  Of course, this whole use case assumes you&#8217;ve committed any previous changes before making the changes you don&#8217;t like.  You do commit incrementally, early, and often, right?<\/p>\n<p>My first instinct was this:<\/p>\n<pre><code>svn revert -R .<\/code><\/pre>\n<p>But that&#8217;s only half the answer.  Files already existing the repository are reverted, but new files and directories still abound.  A check of <code>svn status<\/code> reveals the remaining damage:<\/p>\n<pre><code>?      test\/unit\/user_test.rb\n?      test\/functional\/users_controller_test.rb\n?      test\/fixtures\/users.yml\n?      app\/helpers\/users_helper.rb\n?      app\/models\/user.rb\n?      app\/controllers\/users_controller.rb\n?      app\/views\/users\n?      tmp\/sessions\/ruby_sess.5337b01cd2bbeca8\n?      db\/schema.rb\n?      db\/migrate<\/code><\/pre>\n<p>Assuming you&#8217;re on a Unix-like system (oh, say, OS X), the following will remove all of the offending files and directories:<\/p>\n<pre><code>rm -rf `svn st | sed &#039;s\/\\? *\/\/&#039;`<\/code><\/pre>\n<p>A check of <code>svn status<\/code> should now be blessedly quiet.<\/p>\n<p><strong>Obligatory Nag\/Warning:<\/strong>  Use Caution!  Any command line that begins <code>rm -rf<\/code> is likely to end in tears.  Your Mileage May Vary.  Caveat Emptor.  No Warranty, Expressed or Implied.  Want to double check what you&#8217;re about to trash?  Run the bit inside the backticks (<code>svn st | sed &#039;s\/\\? *\/\/&#039;<\/code>) to see the file list.  Finally, remember to run <code>svn revert -R .<\/code> first!<\/p>","protected":false},"excerpt":{"rendered":"<p>Update 8 Sept: Ryan Bates&#8217; Railscast episode #36 shows you how to setup a new rails project in Subversion, including setting up trunk\/tags\/branches, and a number of tips to make using svn with rails easier. He doesn&#8217;t cover undoing new files, but it&#8217;s a great introduction that I wish I&#8217;d had when I started using [&hellip;]<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-348","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/posts\/348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/comments?post=348"}],"version-history":[{"count":0,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/posts\/348\/revisions"}],"wp:attachment":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/media?parent=348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/categories?post=348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/tags?post=348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}