Fix Subversion conflicts

Got a case where you did a svn up and now you have a bunch of conflicts where you just want to overwrite your changes? I’ve got a little bit of Ruby cleverness for you:


  `svn status`.split("n").grep(/^C/).map { |c| c.scan(/S+/).last }.each { |c| `svn cat #{c} > #{c} && svn resolved #{c}` }

I run this from irb at the root of my Subversion working directory. It makes me happy.

Update: lord that looks ugly on one line!


  status = `svn status`.split("n")
  conflicts = status.grep(/^C/)
  files = conflicts.map { |c| c.scan(/S+/).last }
  conflicts.each do |c|
    `svn cat #{c} > #{c} && svn resolved #{c}`
  end
This entry was posted in Code, Curated and tagged , . Bookmark the permalink.

One Response to Fix Subversion conflicts

  1. You can do this by reverting too I think:

    ruby -e ‘`svn st`.scan(/^C\s+(.*)/){|f| `svn revert #{f}`}’

    or just: svn -R revert . to revert all

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Comments will be sent to the moderation queue.