How do I 'svn add' all unversioned files to SVN?

SvnCommand LineWindows Server-2003

Svn Problem Overview


I'm looking for a good way to automatically 'svn add' all unversioned files in a working copy to my SVN repository.

I have a live server that can create a few files that should be under source control. I would like to have a short script that I can run to automatically add these, instead of going through and adding them one at a time.

My server is running Windows Server 2003 so a Unix solution won't work.

Svn Solutions


Solution 1 - Svn

svn add --force * --auto-props --parents --depth infinity -q

Great tip! One remark: my Eclipse adds new files to the ignore list automatically. It may be a matter of configuration, but anyhow: there is the --no-ignore option that helps.

After this, you can commit:

svn commit -m 'Adding a file'

Solution 2 - Svn

This is a different question to mine but there is an answer there that belongs on this question:

svn status | grep '?' | sed 's/^.* /svn add /' | bash

Solution 3 - Svn

What works is this:

c:\work\repo1>svn add . --force

Adds the contents of subdirectories.

Does not add ignored files.

Lists what files were added.

The dot in the command indicates the current directory, this can replaced by a specific directory name or path if you want to add a different directory than the current one.

Solution 4 - Svn

This worked for me:

svn add `svn status . | grep "^?" | awk '{print $2}'`

(Source)

As you already solved your problem for Windows, this is a UNIX solution (following Sam). I added here as I think it is still useful for those who reach this question asking for the same thing (as the title does not include the keyword "WINDOWS").

Note (Feb, 2015): As commented by "bdrx", the above command could be further simplified in this way:

 svn add `svn status . | awk '/^[?]/{print $2}'`

Solution 5 - Svn

This method should handle filenames which have any number/combination of spaces in them...

svn status /home/websites/website1 | grep -Z "^?" | sed s/^?// | sed s/[[:space:]]*// | xargs -i svn add \"{}\"

Here is an explanation of what that command does:

  • List all changed files.
  • Limit this list to lines with '?' at the beginning - i.e. new files.
  • Remove the '?' character at the beginning of the line.
  • Remove the spaces at the beginning of the line.
  • Pipe the filenames into xargs to run the svn add multiple times.

Use the -i argument to xargs to handle being able to import files names with spaces into 'svn add' - basically, -i sets {} to be used as a placeholder so we can put the " characters around the filename used by 'svn add'.

An advantage of this method is that this should handle filenames with spaces in them.

Solution 6 - Svn

svn add --force .

This will add any unversioned file in the current directory and all versioned child directories.

Solution 7 - Svn

TortoiseSVN has this capability built in, if you're willing to use a non-command-line solution. Just right click on the top level folder and select Add...

Solution 8 - Svn

Use:

svn st | grep ? | cut -d? -f2 | xargs svn add

Solution 9 - Svn

I always use:

Copy&paste

svn st | grep "^\?" | awk "{print \$2}" | xargs svn add $1

Solution 10 - Svn

This is as documented on svn book and the simplest and works perfect for me

svn add * --force

http://svnbook.red-bean.com/en/1.6/svn.ref.svn.c.add.html

Solution 11 - Svn

Since this post is tagged Windows, I thought I would work out a solution for Windows. I wanted to automate the process, and I made a bat file. I resisted making a console.exe in C#.

I wanted to add any files or folders which are not added in my repository when I begin the commit process.

The problem with many of the answers is they will list unversioned files which should be ignored as per my ignore list in TortoiseSVN.

Here is my hook setting and batch file which does that

Tortoise Hook Script:

"start_commit_hook".
(where I checkout) working copy path = C:\Projects
command line: C:\windows\system32\cmd.exe /c C:\Tools\SVN\svnadd.bat
(X) Wait for the script to finish
(X) (Optional) Hide script while running
(X) Always execute the script

svnadd.bat

@echo off

rem Iterates each line result from the command which lists files/folders
rem     not added to source control while respecting the ignore list.
FOR /F "delims==" %%G IN ('svn status ^| findstr "^?"') DO call :DoSVNAdd "%%G"
goto end

:DoSVNAdd
set addPath=%1
rem Remove line prefix formatting from svn status command output as well as
rem    quotes from the G call (as required for long folder names). Then
rem    place quotes back around the path for the SVN add call.
set addPath="%addPath:~9,-1%"
svn add %addPath%

:end

Solution 12 - Svn

for /f "usebackq tokens=2*" %%i in (`svn status ^| findstr /r "^\?"`) do svn add "%%i %%j"

Within this implementation, you will get in trouble in the case your folders/filenames have more than one space like below:

"C:\PROJECTS\BACKUP_MGs_via_SVN\TEST-MG-10\data\destinations\Sega Mega      2"
"C:\PROJECTS\BACKUP_MGs_via_SVN\TEST-MG-10\data\destinations\One space"
"C:\PROJECTS\BACKUP_MGs_via_SVN\TEST-MG-10\data\destinations\Double  space"
"C:\PROJECTS\BACKUP_MGs_via_SVN\TEST-MG-10\data\destinations\Single"

such cases are covered by simple:

for /f "usebackq tokens=1*" %%i in (`svn status ^| findstr /r "^\?"`) do svn add "%%j"

Solution 13 - Svn

If you use Linux or use Cygwin or MinGW in windows you can use bash-like solutions like the following. Contrasting with other similar ones presented here, this one takes into account file name spaces:

svn status| grep ^? | while read line ; do  svn add "`echo $line|cut --complement -c 1,2`" ;done

Solution 14 - Svn

After spending some time trying to figure out how to recursively add only some of the files, i thought it would be valid to share what did work for me:

FOR /F %F IN ('dir /s /b /a:d') DO svn add --depth=empty "%F"
FOR /F %F IN ('dir /s /b /a *.cs *.csproj *.rpt *.xsd *.resx *.ico *.sql') DO svn add "%F"

Here goes some explanation.

The first command adds all the directories. The second command adds only the files accordingly to the specifed patterns.

Let me give more details:

  • FOR: you know, the loop control.
  • /F: means take the files and directories (not sure exactly).
  • %F: its a variable; it will assume the value of each of the listed files at a time; it could have another one-character-name.
  • IN: no need to explain, right?
  • ('dir /s /b /a:d'): the DOS command that will list the directories; in my case /s is recursive, /b is to take only the full path, /a:d means only the directory; change it as you wish keeping the parenthesis and apostrophes.
  • DO: means that what comes next in the command is what will be executed for each directory
  • svn add --depth=empty: it is the desired SVN commando to be run; the depth definition means to add only the directory and not the files inside them.
  • "%F": that's how you use the variable defined earlier.

In the second command, the only differences are the dir command and the svn command, i think it is clear enough.

Solution 15 - Svn

You can use command

svn add * force--

or

svn add <directory/file name>

###If your files/directories are not adding recursively. Then check this.

Recursive adding is default property. You can see in SVN book.

Issue can be in your ignore list or global properties.

I got solution google issue tracker

###Check global properties for ignoring star(*)

  • Right click in your repo in window. Select TortoiseSVN > Properties.
  • See if you don't have a property svn:global-ignores with a value of *
  • If you have property with star(*) then it will ignore recursive adding. So remove this property.

###Check global ignore pattern for ignoring star(*)

  • Right click in your repo in window. Select TortoiseSVN > Settings > General.
  • See in Global Ignore Pattern, if you don't have set star(*) there.
  • If you found star(*), remove this property.

This guy also explained why this property added in my project.

The most like way that it got there is that someone right-clicked a file without any extension and selected TortoiseSVN -> SVN Ignore -> * (recursively), and then committed this.

> You can check the log to see who committed that property change, find > out what they were actually trying to do, and ask them to be more > careful in future. :)

Solution 16 - Svn

You can input the following command on Linux:

find ./ -name "*." | xargs svn add

Solution 17 - Svn

Since he specified Windows, where awk & sed aren't standard:

for /f "tokens=1*" %e in ('svn status^|findstr "^\?"') do svn add "%f"

or in a batch file:

for /f "tokens=1*" %%e in ('svn status^|findstr "^\?"') do svn add "%%f"

Solution 18 - Svn

This is the lazy and dangerous way to synchronize a directory with SVN including new files:

svn rm --keep-local dir
svn add dir

Although this can work in a pinch it can have serious consequences as well. For example, SVN will often lose track of a file's history.

The ideal way to syncronize a directory would be to be able to diff then use svn patch, however this deviates from formats in the diff command and the svn diff command will compare working directory differences rather than differences on the file system level.

Solution 19 - Svn

I think I've done something similar with:

svn add . --recursive

but not sure if my memory is correct ;-p

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
QuestionJerSchneidView Question on Stackoverflow
Solution 1 - SvnRonanView Answer on Stackoverflow
Solution 2 - SvnSam SaffronView Answer on Stackoverflow
Solution 3 - SvnNeutrinoView Answer on Stackoverflow
Solution 4 - SvnlepeView Answer on Stackoverflow
Solution 5 - Svnbailey86View Answer on Stackoverflow
Solution 6 - Svnjmc734View Answer on Stackoverflow
Solution 7 - SvnJohn MeagherView Answer on Stackoverflow
Solution 8 - SvnXiè JìléiView Answer on Stackoverflow
Solution 9 - SvnOritmView Answer on Stackoverflow
Solution 10 - SvnSerjikView Answer on Stackoverflow
Solution 11 - SvnValamasView Answer on Stackoverflow
Solution 12 - SvnolexaView Answer on Stackoverflow
Solution 13 - SvnajaestView Answer on Stackoverflow
Solution 14 - SvnheringerView Answer on Stackoverflow
Solution 15 - SvnKhemraj SharmaView Answer on Stackoverflow
Solution 16 - Svnliu zhijunView Answer on Stackoverflow
Solution 17 - SvnWLHView Answer on Stackoverflow
Solution 18 - SvnjgmjgmView Answer on Stackoverflow
Solution 19 - SvnchakritView Answer on Stackoverflow