我如何“svn add” 所有未版本控制的文件都转移到 SVN 吗?
我正在寻找一种好方法来自动将工作副本中的所有未版本化文件“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
在花了一些时间尝试弄清楚如何仅递归添加某些文件后,我认为分享对我有用的内容是有效的:
这里有一些解释。
第一个命令添加所有目录。 第二个命令仅根据指定模式添加文件。
让我提供更多细节:
在第二个命令中,唯一的区别是 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:
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:
In the second command, the only differences are the dir command and the svn command, i think it is clear enough.
在Linux上可以输入以下命令:
You can input the following command on Linux:
由于他指定了 Windows,因此 awk & sed 不是标准的:
或者在批处理文件中:
Since he specified Windows, where awk & sed aren't standard:
or in a batch file:
这是将目录与 SVN 同步(包括新文件)的懒惰且危险的方法:
虽然这可以在紧要关头发挥作用,但也可能会产生严重的后果。 例如,SVN 通常会丢失文件的历史记录。
同步目录的理想方法是能够比较然后使用 svn patch,但这与 diff 命令中的格式不同,并且 svn diff 命令将比较工作目录差异而不是文件系统级别的差异。
This is the lazy and dangerous way to synchronize a directory with SVN including new files:
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.
我想我已经做了类似的事情:
但不确定我的记忆是否正确;-p
I think I've done something similar with:
but not sure if my memory is correct ;-p
svn add --force * --auto-props --parents --depth infinity -q
很棒的提示! 备注:我的 Eclipse 自动将新文件添加到忽略列表中。 这可能是配置问题,但无论如何:有一个
--no-ignore
选项可以提供帮助。之后,您可以提交:
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:
这是一个不同的问题,但有一个属于这个问题的答案:
This is a different question to mine but there is an answer there that belongs on this question:
有效的方法是:
添加子目录的内容。
不添加被忽略的文件。
列出添加的文件。
命令中的点表示当前目录,如果要添加与当前目录不同的目录,可以将其替换为特定的目录名称或路径。
What works is this:
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.
这对我有用:(
来源)
由于您已经解决了 Windows 的问题,因此这是一个 UNIX 解决方案(遵循 Sam)。 我在这里添加是因为我认为对于那些提出同样问题的人来说它仍然有用(因为标题不包含关键字“WINDOWS”)。
注意(2015 年 2 月):
正如“bdrx”所评论的,上面的命令可以通过这种方式进一步简化:
This worked for me:
(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:
这将在当前目录和所有版本化子目录中添加任何未版本化的文件。
This will add any unversioned file in the current directory and all versioned child directories.
此方法应该处理其中包含任意数量/空格组合的文件名...
以下是该命令的作用的解释:
使用 xargs 的 -i 参数来处理能够将带有空格的文件名导入到 'svn add' 中 - 基本上,-i 将 {} 设置为占位符,这样我们就可以将 " 字符放在 'svn 使用的文件名周围 。
此方法的一个优点是它应该处理其中包含空格的文件名
This method should handle filenames which have any number/combination of spaces in them...
Here is an explanation of what that command does:
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.
如果您愿意使用非命令行解决方案,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...
这是 svn 书中记录的,最简单,对我来说非常完美
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
http://svnbook.red-bean.com/en/1.6/svn.ref.svn.c.add.html
使用:
Use:
我总是使用:
复制和粘贴
I always use:
Copy&paste
由于这篇文章的标签是 Windows,所以我想我应该为 Windows 制定一个解决方案。 我想自动化这个过程,所以我制作了一个bat文件。 我拒绝用 C# 创建 console.exe。
我想添加在开始提交过程时未添加到我的存储库中的任何文件或文件夹。
许多答案的问题是它们会列出未版本控制的文件,这些文件应被忽略为根据我在 TortoiseSVN 中的忽略列表。
这是我的挂钩设置和批处理文件,它确实
Tortoise Hook 脚本:
svnadd.bat
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:
svnadd.bat
在此实现中,如果您的文件夹/文件名有多个空格,如下所示,您将会遇到麻烦:
这种情况可以通过简单的方法来解决:
Within this implementation, you will get in trouble in the case your folders/filenames have more than one space like below:
such cases are covered by simple:
如果您使用 Linux 或在 Windows 中使用 Cygwin 或 MinGW,您可以使用类似 bash 的解决方案,如下所示。 与此处介绍的其他类似方法相比,此方法考虑了文件名空间:
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书籍中看到。
问题可能出在您的忽略列表或全局属性中。
我得到了解决方案google问题跟踪器
检查全局属性以忽略星号(* )
svn:global-ignores
star(*)
的属性,那么它将忽略递归添加。 所以删除这个属性。检查全局忽略模式以忽略星号(*)
star(*)
,请删除此属性。此人还解释了为什么在我的项目中添加此属性。
最常见的方式是有人右键单击一个没有任何扩展名的文件并选择 TortoiseSVN -> SVN 忽略 -> *(递归地),然后提交这个。
You can use command
or
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(*)
TortoiseSVN > Properties
.svn:global-ignores with a value of *
star(*)
then it will ignore recursive adding. So remove this property.Check global ignore pattern for ignoring star(*)
TortoiseSVN > Settings > General
.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.