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.

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

Comments (2)

Anonymous  Dec 4, 2008 11:24:17 AM Hi,

ok, after setting the to be ignored files/folders, they are not shown on 'svn stat' anymore. But when I want to commit files, I do 'svn add project/*' and then the ignored files are still in the list of added files. ("svn commit project" only does not do anything; I need to add files explicitely - svn version 1.4.4). Or do I use a command in a wrong way here?

Any help appreciated!
Sebastian
Dave Minter  Dec 4, 2008 4:55:27 PM I'm not entirely sure what you're describing - without seeing the exact commands that you're issuing it's hard to be certain, but it sounds something like you've applied the ignore list changes to the wrong directory.

In summary you need to:

1. Make the ignore list changes to the directory containing the files to be ignored.
2. Commit the changes to that directory.

My best guess it that you didn't carry out step 2 before you tried to do the commit project/* which is why you're still not getting the benefit!

You can also make the changes recursively so that files matching a pattern in any directory will be ignored, but I'd have to look that up (as noted this post is mostly an aide memoire!).

If the above doesn't help, cut'n'paste into here (or email it if you prefer) the command line output that you're seeing as you try to make the changes and I'll see if I can reproduce the problem and figure out what's going on for you.
Section separator

Add Comments