How do I add all new files to SVN

Svn

Svn Problem Overview


I am using an ORM which generates large amounts of files from a CLI. Is there an easy way to run the svn add on all files within a directory which appear as ? when I run svn status?

Edit These files exist in a directory tree so adding * for one directory will not work.

Svn Solutions


Solution 1 - Svn

This will add all unknown (except ignored) files under the specified directory tree:

svn add --force path/to/dir

This will add all unknown (except ignored) files in the current directory and below:

svn add --force .

Solution 2 - Svn

For reference, these are very similar questions.

These seem to work the best for me. They also work with spaces, and don't re-add ignored files. I didn't see them listed on any of the other answers I saw.

adding:

svn st | grep ^? | sed 's/?    //' | xargs svn add

removing:

svn st | grep ^! | sed 's/!    //' | xargs svn rm

Edit: It's important to NOT use "add *" if you want to keep your ignored files, otherwise everything that was ignored will be re-added.

Solution 3 - Svn

you can just do an svn add path/to/dir/* you'll get warning about anything already in version control but it will add everything that isn't.

Solution 4 - Svn

svn status | grep "^\?" | awk '{print $2}' | xargs svn add

Taken from somewhere on the web but I've been using it for a while and it works well.

Solution 5 - Svn

If svn add whatever/directory/* doesn't work, you can do it the tough way:

svn st | grep ^\? | cut -c 2- | xargs svn add

Solution 6 - Svn

You should be able to run:

svn add *

It may complain about the files that are already under version control, but it will also add the new ones.

You may want to think about whether or not you really want to add these generated files to version control, though. They could be considered derived artifacts, sort of like the compiled code, and thus shouldn't be added. Of course, this is up to you, but its something to think about.

Solution 7 - Svn

The solution

svn status | grep ^? | sed 's/?    //' | xargs svn add

does not work with whitespaces. Instead one can use

svn status | grep ^? | sed 's/^?       //' | xargs -I fn svn add "fn"

(seems like the number of leading blanks is different on my system -- just adjust it).

Solution 8 - Svn

svn add *

should do the job. Just make sure to:

svn commit

afterwards :)

Solution 9 - Svn

On Alpine Linux OS I used this, based on others answers:

svn st | grep ^? | sed 's/? *//' | xargs -I fn svn add "fn"

Solution 10 - Svn

In some shells like fish you can use the ** globbing to do that:

svn add **

Solution 11 - Svn

svn status | grep "^\?" | awk '{ printf("\""); for (f=2; f <= NF; f++) { printf("%s", $f); if (f<NF) printf(" "); } printf("\"\n");}' | xargs svn add

This was based on markb's answer... and a little hunting on the internet. It looks ugly, but it seems to work for me on OS X (including files with spaces).

Solution 12 - Svn

This add all unversioned files even if it contains spaces

svn status | awk '{$1=""; print $0}' | xargs -i svn add "{}"

Solution 13 - Svn

I like these commands as they use svn status to find the new or missing files, which respects files that are ignored.

svn add $( svn status | sed -e '/^?/!d' -e 's/^?//' )

svn rm $( svn status | sed -e '/^!/!d' -e 's/^!//' )

Solution 14 - Svn

Among bash one-liner I think this is the prettiest:

svn status | tee >(awk '/^?/{print $2}' | xargs -r svn add >&2) | awk '/^!/{print $2}' | xargs -r svn delete

It will add all new files and delete all missing files. Use with caution, possibly set an alias for quick access.

NOTE for Macs: in xargs -r is a GNU extension: it might not be supported. In that case just remove it and ignore warnings when there are no files to add or to delete

Solution 15 - Svn

I am a newbie to svn version control. However, for the case when people want to add files without ignoring the already set svn:ignore properties, I solved the issue as below

  1. svn add --depth empty path/to/directory
  2. Execute "svn propset svn:ignore -F ignoreList.txt --recursive" from the location where the ignoreList.txt resides. In my case this file was residing two directories above the "path/to/directory", which I wanted to add. Note that ignoreList.txt contains the file extensions I want svn to ignore, e.g. *.aux etc.
  3. svn add --force path/to/directory/.

The above steps worked.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBrianView Question on Stackoverflow
Solution 1 - SvnjanosView Answer on Stackoverflow
Solution 2 - SvnphazeiView Answer on Stackoverflow
Solution 3 - SvnprodigitalsonView Answer on Stackoverflow
Solution 4 - SvnmarkbView Answer on Stackoverflow
Solution 5 - SvnCarl NorumView Answer on Stackoverflow
Solution 6 - SvnpkaedingView Answer on Stackoverflow
Solution 7 - SvnStefan WitzelView Answer on Stackoverflow
Solution 8 - SvnryanprayogoView Answer on Stackoverflow
Solution 9 - SvnarvatiView Answer on Stackoverflow
Solution 10 - SvnMichaelView Answer on Stackoverflow
Solution 11 - SvnRonView Answer on Stackoverflow
Solution 12 - SvnBharath_145View Answer on Stackoverflow
Solution 13 - SvnTristanView Answer on Stackoverflow
Solution 14 - SvnAndrea RattoView Answer on Stackoverflow
Solution 15 - SvnDeepak TunuguntlaView Answer on Stackoverflow