DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Resolve All SVN Conflicts With The Right Version Of The File

  • submit to reddit
        This small PHP shell script recourses through the subdirectories and looks for files that match the "conflict" files that SVN creates when merging from another branch. It chooses the "right" version of the files and resolves the conflict.

$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("."));
foreach($dir as $file)
  $path = $file->getPathname();
  if (preg_match('/\.merge-right\.r\d+$/', $path, $matches)) {
    $orig = str_replace($matches[0], '' , $path);
    copy($path, $orig);
    $cmd = "svn resolved $orig";


Snippets Manager replied on Wed, 2008/03/12 - 12:21am

The file on the "right" (vs. left) is not always the "right" (correct) file to use. Conflict resolution should be done carefully to not clobber code in older files. Be careful with this script! Use svn up early and often to stay ahead of conflicts. Learn to use diff or find a good diff viewer. Not many on Mac OS X, but Beyond Compare for Windows is fabulous!