Search code examples
bashsvnrevert

Revert svn files by file pattern


I'm trying to find a command (can be bash command) to revert a group of svn files.

Let's say I have some changes in my check-out and I run svn st and get this output:

My-MacBook-2:trunk aetzioni$ svn st
M    SomeFolderA/src/main/java/com/mycompany/package/classA.java
M    SomeFolderA/main/java/com/mycompany/package/classB.java
M    SomeFolderB/src/main/java/com/mycompany/package/classC.java

Now I want to find a command that does svn revert on all the files under SomeFolderA.

I tried something like this:

svn st | grep SomeFolderA | svn revert

But got this error message:

svn: Try 'svn help' for more info
svn: Not enough arguments provided

Solution

  • The way I finally did it is by creating this command:

    svn st | grep SomeFolderA | awk {'print $2'} | xargs svn revert
    

    Explanation:

    1. svn st - Finds all the modified file
    2. grep SomeFolderA - Filters the svn output to only show lines that have SomeFolderA
    3. awk {'print $2'} - removes the M at the beginning of each output line
    4. xargs svn revert - The xargs command uses the output from previous command and passes it, as is, to the svn revert command