`

SVN忽略整个目录

阅读更多

用svn管理代码,一直以来都受到一件不爽事情的困扰:

1)有些文件或文件夹不想在commit的时候看到,虽然他们是non-versioned,比如*.bak.*.class,*.scc(vss文件),目录比如bin/, classes/,还有一些是eclipse之类开发工具生成的文件

2)当错误的将以上那些不想看到的文件加入svn后,该怎么忽略它们

 

google了一下svn ignore,看到了些方法:

 

转自http://www.svn8.com/SVNSY/20090405/4410.html 写道
若想创建了一个文件夹,并且把它加入版本控制,但忽略文件夹中的所有文件的内容:

$ svn mkdir spool
$ svn propset svn:ignore '*' spool
$ svn ci -m 'Adding "spool" and ignoring its contents.'

若想创建一个文件夹,但不加入版本控制,即忽略这个文件夹:

$ mkdir spool
$ svn propset svn:ignore 'spool' .
$ svn ci -m 'Ignoring a directory called "spool".'

若已经创建了文件夹,并加入了版本控制,现在想忽略这个文件夹,但要保持文件夹的内容:

$ svn export spool spool-tmp
$ svn rm spool
$ svn ci -m 'Removing inadvertently added directory "spool".'
$ mv spool-tmp spool
$ svn propset svn:ignore 'spool' .
$ svn ci -m 'Ignoring a directory called "spool".'

 

我看了网上关于svn:ignore的介绍, 说对于没有加入版本控制的,可以直接设定成ignore,但不能对加入版本控制的文件和目录这么做。解决办法是,先删除再ignore, 上面的命令其实也是这个方式,只不过有导出再mv的过程。

命令行方式固然好,但我用的是tortoisesvn,界面操作更加人性化和easy。tortoisesvn下页可以类似的这么做:

1)找到这些文件,直接右键,add to ignore list, 之后可以选择by name,by extention, 选择by extention就能忽略同类文件了。

2)直接在命令模式del /s *.bak ,先把*.bak在本地工作目录删除掉,然后再commit;看需要,再将*.bak 加入ignore

 

 

There may be times when you want to keep certain files out of Subversion. Examples of these include local configuration files and temporary files like those created by vim. Fortunately, Subversion has an option to specify exclusions, via svn:ignore. To do this, run the following in a terminal

svn propedit svn:ignore <parent directory of the files/directories to ignore>

This will open up a text editor where you can specify what to ignore, one file/directory per line. Remember that these are all relative to the parent directory you specified. Two things to note:

  • The command is svn propedit and not svn propset in a normal use case. The latter command is for migrating CVS ignore files, and will produce a Explicit target required error if you attempt to run it on a directory.
  • This only works for items not yet in the repository. If the file or directory was previously placed in Subversion, specifying it in the ignore file won’t have any effect.

Check out the chapter on ignoring unversioned items of the online Subversion book for more information, such as what file pattern syntax you can use in the ignore file.

 

 

 

 

看了上面两篇转载的文章,加上自己的实践总结如下:

 

Request:

我有一个工程,工程名为simple,采用maven进行依赖管理,在check in时我不想工程下maven产生的target目录被提交到SVN(包括目录下所有文件和目录本身)。

 

Solution:

1) 要被忽略的目录必须是未版本化的目录,如果已被版本化,设置svn:ignore不起作用(除非在本地删除提交后再设置或直接svn del url后再设置)。

2) 要被忽略的目录的父目录必须是已版本化的目录。

3) 命令:

      a) svn pe svn:ignore simple

      回车后在打开的文本编辑器里输入pattern:target

      b) svn ps svn:ignore "target" simple

      此命令直接在“”中加上pattern,不会打开文本编辑器。

      命令的参数应该是要被忽略的目录的父目录,pattern里面写要被忽略的目录,这点我弄了很久才搞明白。

      上面老外的文章里写的“The command is svn propedit and not svn propset in a normal use case. The latter command is for migrating CVS ignore files, and will produce a Explicit target required error if you attempt to run it on a directory”并不正确,svn ps可以用,但是是采用 b) 形式的命令。 svn pe和svn ps都可以设置svn:ignore属性,只是usage不同而已: svn pe svn:ignore parent_dir  VS svn ps svn:ignore "pattern" parent_dir.  如果两个命令的pattern相同,他们的效果是一样的。若有多个pattern,使用svn pe,一行写一个pattern

 

 

Update:

svn ps 也可以设置多个pattern:

svn ps svn:ignore "pattern1 \

pattern 2"

需要在不同pattern之间用回车隔开, 不可以是空格.用"\"分隔不同行

或者写在文件里, 然后从文件导入

svn ps svn:ignore -F svnignore dir

如果要递归设置所有目录:

svn ps -R svn:ignore -F svnignore parent_dir

如果只想设置一个maven项目下各moudle项目的根目录可以结合find命令:

find . -type d -maxdepth 1 -exec bash -c "svn ps svn:ignore -F svnignore {}" \;

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics