我如何“svn add” 所有未版本控制的文件都转移到 SVN 吗?

发布于 2024-07-26 12:00:03 字数 273 浏览 4 评论 0原文

我正在寻找一种好方法来自动将工作副本中的所有未版本化文件“svn 添加”到我的 SVN 存储库。

我有一个实时服务器,可以创建一些应受源代码控制的文件。 我想要一个简短的脚本,我可以运行它来自动添加这些内容,而不是一次逐一添加它们。

我的服务器运行的是 Windows Server 2003,因此 Unix 解决方案不起作用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(19

戏蝶舞 2024-08-02 12:00:04

在花了一些时间尝试弄清楚如何仅递归添加某些文件后,我认为分享对我有用的内容是有效的:

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"

这里有一些解释。

第一个命令添加所有目录。 第二个命令仅根据指定模式添加文件。

让我提供更多细节:

  • FOR:你知道,循环控制。
  • /F:表示获取文件和目录(不确定)。
  • %F:它是一个变量; 它将同时采用列出的每个文件的值; 它可以有另一个单字符名称。
  • IN:不用解释吧?
  • ('dir /s /b /a:d'):列出目录的 DOS 命令; 在我的例子中, /s 是递归的, /b 表示仅采用完整路径, /a:d 表示仅采用目录; 根据需要更改它,保留括号和撇号。
  • DO:表示命令中接下来的内容是将针对每个目录执行的内容
  • svn add --depth=empty:它是要运行的所需 SVN 命令; 深度定义意味着仅添加目录而不添加其中的文件。
  • “%F”:这就是您使用前面定义的变量的方式。

在第二个命令中,唯一的区别是 dir 命令和 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.

尘曦 2024-08-02 12:00:04

在Linux上可以输入以下命令:

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

You can input the following command on Linux:

find ./ -name "*." | xargs svn add
尹雨沫 2024-08-02 12:00:04

由于他指定了 Windows,因此 awk & sed 不是标准的:

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

或者在批处理文件中:

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

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"
北恋 2024-08-02 12:00:04

这是将目录与 SVN 同步(包括新文件)的懒惰且危险的方法:

svn rm --keep-local dir
svn add dir

虽然这可以在紧要关头发挥作用,但也可能会产生严重的后果。 例如,SVN 通常会丢失文件的历史记录。

同步目录的理想方法是能够比较然后使用 svn patch,但这与 diff 命令中的格式不同,并且 svn diff 命令将比较工作目录差异而不是文件系统级别的差异。

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.

你的笑 2024-08-02 12:00:04

我想我已经做了类似的事情:

svn add . --recursive

但不确定我的记忆是否正确;-p

I think I've done something similar with:

svn add . --recursive

but not sure if my memory is correct ;-p

吾性傲以野 2024-08-02 12:00:03

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

很棒的提示! 备注:我的 Eclipse 自动将新文件添加到忽略列表中。 这可能是配置问题,但无论如何:有一个 --no-ignore 选项可以提供帮助。

之后,您可以提交:

svn commit -m 'Adding a file'

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'
向日葵 2024-08-02 12:00:03

这是一个不同的问题,但有一个属于这个问题的答案:

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

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
我的影子我的梦 2024-08-02 12:00:03

有效的方法是:

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

添加子目录的内容。

不添加被忽略的文件。

列出添加的文件。

命令中的点表示当前目录,如果要添加与当前目录不同的目录,可以将其替换为特定的目录名称或路径。

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.

菩提树下叶撕阳。 2024-08-02 12:00:03

这对我有用:(

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

来源)

由于您已经解决了 Windows 的问题,因此这是一个 UNIX 解决方案(遵循 Sam)。 我在这里添加是因为我认为对于那些提出同样问题的人来说它仍然有用(因为标题不包含关键字“WINDOWS”)。

注意(2015 年 2 月):
正如“bdrx”所评论的,上面的命令可以通过这种方式进一步简化:

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

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}'`
静待花开 2024-08-02 12:00:03
svn add --force .

这将在当前目录和所有版本化子目录中添加任何未版本化的文件。

svn add --force .

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

深海夜未眠 2024-08-02 12:00:03

此方法应该处理其中包含任意数量/空格组合的文件名...

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

以下是该命令的作用的解释:

  • 列出所有更改的文件。
  • 将此列表限制为带有“?”的行 在开头 - 即新文件。
  • 去除 '?' 字符位于行的开头。
  • 删除行首的空格。
  • 将文件名通过管道传输到 xargs 中以多次运行 svn add 。

使用 xargs 的 -i 参数来处理能够将带有空格的文件名导入到 'svn add' 中 - 基本上,-i 将 {} 设置为占位符,这样我们就可以将 " 字符放在 '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.

像极了他 2024-08-02 12:00:03

如果您愿意使用非命令行解决方案,TortoiseSVN 内置了此功能。 只需右键单击顶级文件夹并选择添加...

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...

沩ん囻菔务 2024-08-02 12:00:03

这是 svn 书中记录的,最简单,对我来说非常完美

svn add * --force

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

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

猫性小仙女 2024-08-02 12:00:03

使用:

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

Use:

svn st | grep ? | cut -d? -f2 | xargs svn add
姐不稀罕 2024-08-02 12:00:03

我总是使用:

复制和粘贴

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

I always use:

Copy&paste

svn st | grep "^\?" | awk "{print \$2}" | xargs svn add $1
ゝ杯具 2024-08-02 12:00:03

由于这篇文章的标签是 Windows,所以我想我应该为 Windows 制定一个解决方案。 我想自动化这个过程,所以我制作了一个bat文件。 我拒绝用 C# 创建 console.exe。

我想添加在开始提交过程时未添加到我的存储库中的任何文件或文件夹。

许多答案的问题是它们会列出未版本控制的文件,这些文件应被忽略为根据我在 TortoiseSVN 中的忽略列表。

这是我的挂钩设置和批处理文件,它确实

Tortoise Hook 脚本:

"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

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
陈甜 2024-08-02 12:00:03
for /f "usebackq tokens=2*" %%i in (`svn status ^| findstr /r "^\?"`) do svn add "%%i %%j"

在此实现中,如果您的文件夹/文件名有多个空格,如下所示,您将会遇到麻烦:

"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"

这种情况可以通过简单的方法来解决:

for /f "usebackq tokens=1*" %%i in (`svn status ^| findstr /r "^\?"`) do svn add "%%j"
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"
千と千尋 2024-08-02 12:00:03

如果您使用 Linux 或在 Windows 中使用 Cygwin 或 MinGW,您可以使用类似 bash 的解决方案,如下所示。 与此处介绍的其他类似方法相比,此方法考虑了文件名空间:

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

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
亣腦蒛氧 2024-08-02 12:00:03

您可以使用命令

svn add * force--

svn add <directory/file name>

如果您的文件/目录没有递归添加, 。 然后检查一下。

递归添加是默认属性。 你可以在SVN书籍中看到。

问题可能出在您的忽略列表或全局属性中。

我得到了解决方案google问题跟踪器

检查全局属性以忽略星号(* )

  • 右键单击窗口中的存储库。 选择TortoiseSVN > 属性。
  • 看看你是否没有值为 * 的属性 svn:global-ignores
  • 如果你有带有 star(*) 的属性,那么它将忽略递归添加。 所以删除这个属性。

检查全局忽略模式以忽略星号(*)

  • 右键单击​​窗口中的存储库。 选择TortoiseSVN > 设置> 一般。
  • 如果您没有在那里设置star(*),请参阅全局忽略模式。
  • 如果您发现star(*),请删除此属性。

此人还解释了为什么在我的项目中添加此属性。

最常见的方式是有人右键单击一个没有任何扩展名的文件并选择 TortoiseSVN -> 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. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文