Unix command line tip of the day: How to recursively add all newly added files to Subversion in an existing working copy


When using Subversion for version control, if you have a working copy checked out and then you want to add a variety of new files and directories to the existing ones, you might do something like this:

[code]cp -R newfiles/* files/[/code]

Unfortunately, svn add only will add files or directories in the immediate directory unless you explicitly specify each new file or directory to add when you are adding to directories that already exist.

This means that if there is a directory called images in both files and newfiles that is already under version control, and inside of newfiles/images/ is a new directory called icons, running svn add * from within the files directory will NOT recursively add it as you might hope it would.

Here is a one-line command-line way to find all new / unknown files using Subversion’s status command and recursively add all of the found files to your current working copy, ready to commit.

[code]svn st | grep ? | sed ‘s/^?[\t]*//;’ | xargs svn add[/code]

This runs Subversion status, then filters the resulting list using grep to find only entries with a ? in front of them (unknown files), then pipes the resulting list through sed to remove the question mark and the leading space, then pipes the resulting set of files / directories into Subversion add using xargs, which operates on each supplied line.

, , , ,

One response to “Unix command line tip of the day: How to recursively add all newly added files to Subversion in an existing working copy”

  1. Thanks for that – I’ll really have to learn to use sed!

    I changed the command to allow me to add directories and files with spaces in them (I work with the svn repositories in windows too…)

    svn st | grep ? | sed ‘s/^?[\t]*//;’ | sed ‘s/^[ ]*//g;’ | sed ‘s/\s/\\ /g;’ | xargs svn add

    seems to work ok – I might even refactor the regular expressions when I have the time – cheers again!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

sell diamonds