Who knew it would be so hard to get svn to ignore some files and directories?

I’m working on an Android project, and I wanted svn to stop looking at me questioningly regarding files and directories that were automatically generated every time I built my source code. Basically, I needed svn to completely ignore the following:

  • bin/ and gen/: directories with generated code
  • proguard/: directory generated by my editor, Eclipse
  • .classpath and .project: Eclipse project files
  • local.properties: local config file
  • Thumbs.db: annoying Windows thumbnail database files that are EVERYWHERE
  • All built Android files, which have the extension .apk or .ap_
  • All Java class files, which have the extension .class

I didn’t think it would too difficult to get svn to ignore some files for me, but it turns out that svn really likes to pay attention to my files. Hours passed before I finally got svn to relax and ignore what I wanted it to. Below the cut, I share my newfound wisdom with you.

The svn:ignore property

svn has properties, which let you specify how your repository should be handled. One of these properties is svn:ignore. How this works is that you use the command svn propset to set the property svn:ignore on a particular directory. You give svn:ignore a value, which is a file name pattern. Then, svn will ignore all items in this directory whose name matches the pattern. For example:

svn propset svn:ignore *.class .

Here, you’re telling svn to set the svn:ignore property, and what you want ignored are all files in the current directory (.) with the extension .class.

If you do svn status after executing that line, you’ll find that svn will not show you any *.class files in the current directory that are not under version control. Ah, so much less output to sift through now. If you want svn status to tell you about the ignored files as well, you can do:

svn status --no-ignore

On ignoring directories

A short note that when specifying a directory to be ignored, you must not put any slashes before or after it! To ignore the directory “bin”, just type “bin”. “/bin” or “bin/” will crash and burn, and your “bin” directory will not be ignored. In short:

svn propset svn:ignore bin . # yes
svn propset svn:ignore /bin . # nope
svn propset svn:ignore bin/ . # nope

Recursive property setting with -R

So, that was simple enough right? However, the command we used above only sets svn:ignore for the current directory: svn will not ignore *.class files in subdirectories! Fortunately, if we want *.class to be ignored in all subdirectories as well, we just need to add the -R (or --recursive) flag to specify that the command should be applied recursively:

svn propset svn:ignore -R *.class .

Like magic, *.class files are now ignored! Life is beautiful.

Ignoring multiple file types and items

Say you execute the following lines of code to ignore *.class, *.apk, and Thumbs.db files:

svn propset svn:ignore -R *.class .
svn propset svn:ignore -R *.apk .
svn propset svn:ignore -R Thumbs.db .

Now, you do svn status, and you see…what?! *.class files? *.apk files? In fact, the only files that are being ignored are those pesky Thumbs.db files. As I discovered, whenever you set svn:ignore, you’re overwriting whatever value was previously set. So, when we did svn propset for *.apk, we overwrote the svn:ignore setting for *.class, and the svn:ignore setting for *.apk was overwritten when we did svn propset for Thumbs.db!

To ignore multiple items, you’ll need to be tricky. Use quotations and put each name pattern to be ignored on its own line, and you’ll get to ignore a long list of items:

svn propset svn:ignore -R "*.class
> *.apk
> Thumbs.db" .

The > are, of course, just my shell prompts. You don’t type those in.

“svn, ignore all the names on this blacklist!”: the -F flag

If you added a new subdirectory after setting svn:ignore, your new subdirectory and everything in it will not be subject your svn:ignore settings! You will have to run svn propset again. Clearly, it’s not good to set svn:ignore manually like this every time: you’re wasting time, you might make typos, you might forget to include a pattern, and if you’re working on a team, you can’t share your awesome svn:ignore settings with everyone else!

Have no fear though, for the -F (--file) flag is here to rescue you! With -F, you can specify a file that contains a list of file name patterns to ignore. For example, this was my file for my Android project:

bin
gen
proguard
.classpath
.project
local.properties
Thumbs.db
*.apk
*.ap_
*.class
*.dex

I saved this file as .svnignore, and then I did:

svn propset svn:ignore -R -F .svnignore .

What did this do? Starting from the current directory, it recursively set svn:ignore with all of the patterns listed in .svnignore for each directory. Magic! And the best thing is that you can commit .svnignore to your repository as well, so that you and/or your team can use it again it the future.

Things to watch out for with this approach

Great power comes with great responsibility, and this is no exception. Notice that every pattern in the file was ignored for every subdirectory. This means that any directories called “bin”, “gen”, or “proguard” will be ignored by svn in my example, no matter how deeply these directories are nested. This is fine for my project, but if that’s not true for you, you need to remember to go to those directories and change the svn:ignore setting. (You might want to write a shell script to help you with all this!)

Living with your ignorance

Now that you have svn:ignore settings applied, here are some commands to help you live with them more comfortably:

List all properties (including svn:ignore) set for the current directory. You can optionally specify a path, or use -v (--verbose) will list all the file patterns being ignored.

svn proplist -v [PATH]

Remove all your svn:ignore settings for the current directory. You can optionally specify a path, or use -R (--recursive) to delete the property recursively.

svn propdel svn:ignore [PATH]

As mentioned earlier, this will include all ignored files in your svn status output:

svn status --no-ignore

Conclusion

And that is probably more than you ever wanted to know about ignoring files and directories in svn! So much fun, isn’t it? If you have any questions, comments, or errors to point out, don’t be shy — leave a message below!

Getting svn to ignore files and directories的更多相关文章

  1. How to ignore files and directories in subversion?

    Step 1 Copy the files and directories to other place. Step 2 Delete the files and directories. Step ...

  2. 10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories

    The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk ...

  3. Files and Directories

    Files and Directories Introduction     In the previous chapter we coveredthe basic functions that pe ...

  4. 【原】The Linux Command Line - Manipulation Files And Directories

    cp - Copy Files and directories mv - move/rename files and directories mkdir - create directories rm ...

  5. Notes for Apue —— chapter 4 Files and Directories(文件和目录)

    4.1 Introduction 4.2 stat, fstat, fstatat, and lstat Functions The lstat function is similar to stat ...

  6. Ignore files which are already versioned

    If you accidentally added some files which should have been ignored, how do you get them out of vers ...

  7. 第14月第30天 svn 撤销ignore revert

    1. 直接到被ignore的位置,执行: svn add <你被ignore的文件名> --no-ignore –no-ignore是取消忽略 如果是add目录,你可以: svn add ...

  8. UNIX高级环境编程(4)Files And Directories - umask、chmod、文件系统组织结构和链接

    本篇主要介绍文件和文件系统中常用的一些函数,文件系统的组织结构和硬链接.符号链接. 通过对这些知识的了解,可以对Linux文件系统有更为全面的了解.   1 umask函数 之前我们已经了解了每个文件 ...

  9. UNIX高级环境编程(5)Files And Directories - 文件相关时间,目录文件相关操作

     1 File Times 每个文件会维护三个时间字段,每个字段代表的时间都不同.如下表所示: 字段说明: st_mtim(the modification time)记录了文件内容最后一次被修改的时 ...

随机推荐

  1. editplus设置自动换行方法 editplus自动换行设置步骤

    原文链接:https://www.jb51.net/softjc/165897.html 发布时间:2014-05-14 17:03:54   作者:佚名    我要评论 editplus自动换行设置 ...

  2. Map、Set、List 集合 差别 联系

    提到集合之前,先说说数组Array和集合的区别:   (1)数组是大小固定的,并且同一个数组只能存放类型一样的数据(基本类型/引用类型)   (2)JAVA集合可以存储和操作数目不固定的一组数据. ( ...

  3. SQL Server 2008中SQL增强之一:Values新用途 001

    连接集合 select '1' as id,'wang' as name union select '2' as id,'admin' as name 现在可以这么写了 select id,name ...

  4. Mysql 表 创建 / 删除(基础3)

    创建表 语法:  #进入数据库 mysql> use mydb123; Database changedmysql> select database();+------------+| d ...

  5. myeclipse2014安装aptana3.4.0插件(转)

    1.下载aptana3.4.0_eclipse的zip包  http://pan.baidu.com/s/1qXOiZl6 或者是:https://pan.baidu.com/s/1jIqOYcI 2 ...

  6. mysql5.6 基于Binlog ROW记录方式进行数据恢复(无备份)

    数据库配置注意事项 /etc/my.cnf 必须要开户binlog支持,字符集要求 是utf8 binlog类型为row server-id=121 log_bin=/home/mysqllog bi ...

  7. linux下的C++项目创建

    CMake项目的完整构建 Linux下的CMake项目通常由几个文件夹组成.小伙伴们可以先在自己的电脑上新建一个文件夹,作为你代码的根目录,然后往里面建几个子文件夹,这里并不涉及具体的代码,只是可以作 ...

  8. 100-days: Six

    Title: School lessons (be) to cover sexting, FGM and mental health(精神健康) be to do sth 将要做某事  =>  ...

  9. FortiGate软件版本升级

    1.Web界面升级 1)注意:升级前,务必做好配置备份 2)要点 1.FortiGate防火墙的每款型号都有单独的版本文件,升级前务必确认下当前的设备型号: 2.升级包的后缀名必须为.out,前缀任意 ...

  10. 浅谈Java代理一:JDK动态代理-Proxy.newProxyInstance

    浅谈Java代理一:JDK动态代理-Proxy.newProxyInstance java.lang.reflect.Proxy:该类用于动态生成代理类,只需传入目标接口.目标接口的类加载器以及Inv ...