GeekLondon.com Help icon Syndication Feed icon 

Subversion and svn:ignore

Adding files to the ignore list in Subversion is one of those tasks that I do so infrequently that whenever it comes up I've forgotten the syntax. Next time I'll have this handy blog entry to remind me.

Typically I want to do this to hide Eclipse project artifacts and Maven build targets from Subversion. So here's how to do that.

Firstly we add the project non-recursively so that we don't automatically add the things we want to put into the ignore list. Adding the project to subversion creates the .svn directory which tracks properties set on the directory and is therefore necessary for managing the ignore list.

dcminter@treacle:~$ svn add project --non-recursive
A         project

Now we have somewhere to keep the properties associated with the project directory we can edit them. This next command opens up the default text editor (the same one you use to enter commit messages).

dcminter@treacle:~$ svn propedit svn:ignore project

In the editor you enter the list of files and directories that you want to mark as being ignored, and then save and exit.

.project
.classpath
.settings
target

When you exit you should then see the success message.

dcminter@treacle:~$ svn propedit svn:ignore project
Set new value for property 'svn:ignore' on 'project'

You can use the svn propget command to verify the values that you have set without needing to go back into the editor.

dcminter@treacle:~$ svn propget svn:ignore project
.project
.classpath
.settings
target

Commit the project directory.

dcminter@treacle:~$ svn commit project

Enter an appropriate update message in the editor. Note that only the project directory is included in this commit.

Modified

Adding the new project directory with an appropriate ignore list.

--This line, and those below, will be ignored--

AM   project

You should now see the commit confirmation.

dcminter@treacle:~$ svn commit project
Adding         project

Committed revision 97.

Now if you do an ls and then a svn stat you will see that the specified files and directories are now being ignored by Subversion.

dcminter@treacle:~$ cd project/
dcminter@treacle:~$ ls -al
total 24
drwxr-xr-x  6 dcminter dcminter 4096 2007-12-24 15:15 .
drwxr-xr-x 10 dcminter dcminter 4096 2007-12-24 15:21 ..
-rw-r--r--  1 dcminter dcminter    0 2007-12-24 15:07 .classpath
-rw-r--r--  1 dcminter dcminter    0 2007-12-24 15:07 .project
drwxr-xr-x  2 dcminter dcminter 4096 2007-12-24 15:08 .settings
drwxr-xr-x  2 dcminter dcminter 4096 2007-12-24 15:08 src
drwxr-xr-x  6 dcminter dcminter 4096 2007-12-24 15:21 .svn
drwxr-xr-x  2 dcminter dcminter 4096 2007-12-24 15:08 target
dcminter@treacle:~/project$ svn stat
?      src
dcminter@treacle:~/project$

Really the only important bit of the above to remember is the use of the svn propedit svn:ignore path command, but sometimes it can help to have a bit of context.

Comments (0)

Posted at Dec 24, 2007 3:35:43 PM, and last updated Jan 30, 2008 5:34:29 PM