791

I just started using SVN, and I have a cache directory that I don't need under source control. How can I ignore the whole directory/folder with SVN?

I am using Versions and TextMate on OS X and commandline.

2

22 Answers 22

831

Set the svn:ignore property of the parent directory:

svn propset svn:ignore dirname .

If you have multiple things to ignore, separate by newlines in the property value. In that case it's easier to edit the property value using an external editor:

svn propedit svn:ignore .
15
  • 2
    @Kouber: Your problem is that the shell expansion does not know about svn:ignore properties. So using '*' as parameter explicityl passes tmp to the commit command. Try something like 'svn commit -m "More accents" .' May 6, 2011 at 10:58
  • 5
    Thanks for the answer. Pico as an editor: svn propedit svn:ignore . --editor-cmd pico
    – hade
    Sep 15, 2011 at 8:43
  • 164
    Note: This won't work if the directory is already "in" svn. svn rm --keep-local dirname first. (My svn stat output was huge and I bumped my head into this for a while.) May 2, 2012 at 16:24
  • 12
    If you want to ignore more than one file/folder, add all of their names to a txt file, one line each, and use the following variant: svn propset svn:ignore -F file.txt .
    – petervaz
    Aug 7, 2012 at 19:22
  • 7
    Make sure to check if there is already ignored paths with svn propget svn:ignore or svn propset svn:ignore dirname . will overwrite the currently ignored paths. Best to use svn propedit svn:ignore .. If you already overwritten the svn:ignore use svn proplist -v <PATH>|<URL> to get the current values for your specific path then revert that by copy/paste into svn propedit svn:ignore ..
    – bucabay
    Feb 22, 2018 at 13:11
418

Here's an example directory structure:

\project
    \source
    \cache
    \other

When in project you see that your cache directory is not added and shows up as such.

> svn status
M  source
?  cache

To set the ignore property, do

svn propset svn:ignore cache .

where svn:ignore is the name of the property you're setting, cache is the value of the property, and . is the directory you're setting this property on. It should be the parent directory of the cache directory that needs the property.

To check what properties are set:

> svn proplist
Properties on '.':
  svn:ignore

To see the value of svn:ignore:

> svn propget svn:ignore
cache

To delete properties previously set:

svn propdel svn:ignore
2
  • 19
    One tricky point here that I stumbled over. Make sure you do not add a trailing slash to dirname. For example, when typing svn propset svn:ignore dirname, if you allow the (bash) shell to fill in the dirname for you, it will add that trailing slash, leaving you with the command svn propset svn:ignore dirname/, which doesn't result in the folder being ignored. At least, that was my experience. Apr 9, 2012 at 6:57
  • 7
    The 'cache' dir still will be listed in 'svn st'. Is there a way to remove it from the view? (without delete from the disk) Aug 1, 2016 at 20:45
136

Important to mention:

On the commandline you can't use

svn add *

This will also add the ignored files, because the command line expands * and therefore svn add believes that you want all files to be added. Therefore use this instead:

svn add --force .
1
  • do exactly as @binco said: svn add --force * WON'T work. Use the dot, not the star.
    – manuell
    Jun 1, 2015 at 16:31
84

Since I spent a while trying to get this to work, it should be noted that if the files already exist in SVN, you need to svn delete them, and then edit the svn:ignore property.

I know that seems obvious, but they kept showing up as ? in my svn status list, when I thought it would just ignore them locally.

1
  • 9
    Don't forget to use the --keep-local option when deleting the files if you just want to ignore them and not actually delete them. Apr 29, 2014 at 20:00
77

To expand slightly, if you're doing this with the svn command-line tool, you want to type:

svn propedit svn:ignore path/to/dir

which will open your text-editor of choice, then type '*' to ignore everything inside it, and save+quit - this will include the directory itself in svn, but ignore all the files inside it, to ignore the directory, use the path of the parent, and then type the name of the directory in the file. After saving, run an update ('svn up'), and then check in the appropriate path.

1
  • 8
    Very good point, thank you. All other answers missed case of nested directories. So the above example (working) you then type in editor ignored_directory (which is by assumption one level below path/to/dir). This won't work though: svn propedit svn:ignore . and then typing path/to/dir/ignored_directory in editor. IOW: SVN matches objects one level down at a time. Mar 10, 2010 at 7:43
31

Set the svn:ignore property on the parent directory:

$ cd parentdir
$ svn ps svn:ignore . 'cachedir'

This will overwrite any current value of svn:ignore. You an edit the value with:

$ svn pe svn:ignore .

Which will open your editor. You can add multiple patterns, one per line.

You can view the current value with:

$ svn pg svn:ignore .

If you are using a GUI there should be a menu option to do this.

1
  • 4
    svn ps svn:ignore . 'cachedir' results in cachedir is not under version control. changing to svn ps svn:ignore 'cachedir' . worked for me
    – DiCaprio
    Apr 23, 2015 at 11:48
25

Thanks for all the contributions above. I would just like to share some additional information from my experiences while ignoring files.


When the folders are already under revision control

After svn import and svn co the files, what we usually do for the first time.

All runtime cache, attachments folders will be under version control. so, before svn ps svn:ignore, we need to delete it from the repository.

With SVN version 1.5 above we can use svn del --keep-local your_folder, but for an earlier version, my solution is:

  1. svn export a clean copy of your folders (without .svn hidden folder)
  2. svn del the local and repository,
  3. svn ci
  4. Copy back the folders
  5. Do svn st and confirm the folders are flagged as '?'
  6. Now we can do svn ps according to the solutions

When we need more than one folder to be ignored

  • In one directory I have two folders that need to be set as svn:ignore
  • If we set one, the other will be removed.
  • Then we wonder we need svn pe

svn pe will need to edit the text file, and you can use this command if required to set your text editor using vi:

export SVN_EDITOR=vi
  1. With "o" you can open a new line
  2. Type in all the folder names you want to ignore
  3. Hit 'esc' key to escape from edit mode
  4. Type ":wq" then hit Enter to save and quit

The file looks something simply like this:

runtime
cache
attachments
assets
1
  • you can also use svn propset svn:ignore -F .ignorethesefiles ., which will use the contents of the file. I like keeping it around so you know what is ignored. Edits require followup propset. Mar 17, 2015 at 19:13
22

Remove it first...

If your directory foo is already under version control, remove it first with:

svn rm --keep-local foo

...then ignore:

svn propset svn:ignore foo .
0
14

If you are using the particular SVN client TortoiseSVN, then on commit, you have the option of right clicking items and selecting "Add to ignore list".

12

...and if you want to ignore more than one directory (say build/ temp/ and *.tmp files), you could either do it in two steps (ignoring the first and edit ignore properties (see other answers here) or one could write something like

svn propset svn:ignore "build
temp
*.tmp" .

on the command line.

0
11

The command to ignore multiple entries is a little tricky and requires backslashes.

svn propset svn:ignore "cache\
tmp\
null\
and_so_on" .

This command will ignore anything named cache, tmp, null, and and_so_on in the current directory.

3
  • 6
    And just to clarify: The backslash here is not a feature of svn; it's simply a way to enter a multi-line string on the shell. You can also use an editor and just write multiple lines.
    – sleske
    Oct 25, 2011 at 9:20
  • Backslash is not required for bash. bash is smart enough to know that a " is open and not to process the line. All you need to do is press enter after cache, tmp, and null. You will see that bash changes the prompt to a > so that you know you are still entering the command. An alternative is to start typing the command (svn), then press esc then v. That will allow you to enter the command in the editor. press ZZ when done to execute the command. if you change your mind and do not want to execute, then :q!. Jun 23, 2012 at 20:52
  • 2
    svn propset svn:ignore -F .ignorethesefiles . will allow you to use a file. And as mentioned, you always have propedit. Mar 17, 2015 at 19:15
6

Bash oneliner for multiple ignores:

svn propset svn:ignore ".project"$'\n'".settings"$'\n'".buildpath" "yourpath"
1
  • Since $'somestring' indicates a string literal with escape sequences, you can just write this shorter and easier as svn propset svn:ignore $'.project\n.settings\n.buildpath' "yourpath"
    – kvantour
    Jan 21, 2021 at 16:24
5

I had problems getting nested directories to be ignored; the top directory I wanted to ignore wouldn't show with 'svn status' but all the subdirs did. This is probably self-evident to everyone else, but I thought I'd share it:

EXAMPLE:

/trunk

/trunk/cache

/trunk/cache/subdir1

/trunk/cache/subdir2

cd /trunk
svn ps svn:ignore . /cache
cd /trunk/cache
svn ps svn:ignore . *
svn ci
4

If your project directory is named /Project, and your cache directory is named /Project/Cache, then you need to set a subversion property on /Project. The property name should be "svn:ignore" and the property value should be "Cache".

Refer to this page in the Subversion manual for more on properties.

4

Jason's answer will do the trick. However, instead of setting svn:ignore to "." on the cache directory, you may want to include "cache" in the parent directory's svn:ignore property, in case the cache directory is not always present. I do this on a number of "throwaway" folders.

4

"Thank-you" svn for such a hideous, bogus and difficult way to ignore files.

So I wrote a script svn-ignore-all:

#!/bin/sh

# svn-ignore-all

# usage: 
#   1. run svn status to see what is going on at each step 
#   2. add or commit all files that you DO want to have in svn
#   3. remove any random files that you don't want to svn:ignore
#   4. run this script to svn:ignore everything marked '?' in output of `svn status`

svn status |
grep '^?' |
sed 's/^? *//' |
while read f; do
    d=`dirname "$f"`
    b=`basename "$f"`
    ignore=`svn propget svn:ignore "$d"`
    if [ -n "$ignore" ]; then
        ignore="$ignore
"
    fi
    ignore="$ignore$b"
    svn propset svn:ignore "$ignore" "$d"
done

Also, to ignore specific list of files / pathnames, we can use this variant svn-ignore. I guess svn-ignore-all should really be like xargs svn-ignore.

#!/bin/sh

# svn-ignore

# usage:
#   svn-ignore file/to/ignore ...

for f; do
    d=`dirname "$f"`
    b=`basename "$f"`
    ignore=`svn propget svn:ignore "$d"`
    if [ -n "$ignore" ]; then
        ignore="$ignore
"
    fi
    ignore="$ignore$b"
    svn propset svn:ignore "$ignore" "$d"
done

One more thing: I tend to pollute my svn checkouts with many random files. When it's time to commit, I move those files into an 'old' subdirectory, and tell svn to ignore 'old'.

2
  • Hey Sam, that's a nice script. Question popped up in my head: is it perhaps that the problem comes from the fact that ignoring an entire folder that is part of the repository doesn't work, so we end up with those '?' files which are basically modified files in folders we added to the ignore list? I just wonder if there's a way around your script, as it would be tedious to run it all the time. Do you?
    – SQRCAT
    Sep 15, 2014 at 19:41
  • no, I don't really use it! just try to clean up my files Sep 17, 2014 at 13:04
3

If you are using a frontend for SVN like TortoiseSVN, or some sort of IDE integration, there should also be an ignore option in the same menu are as the commit/add operation.

3

TO KEEP DIRECTORIES THAT SVN WILL IGNORE:

  1. this will delete the files from the repository, but keep the directory under SVN control:

svn delete --keep-local path/directory_to_keep/*

  1. then set to ignore the directory (and all content):

svn propset svn:ignore "*" path/directory_to_keep

2

Set the svn:ignore property. Most UI svn tools have a way to do this as well as the command line discussion in the link.

1

Since you're using Versions it's actually really easy:

  • Browse your checked-out copy
  • Click the directory to ignore
  • In the "Ignore box on the right click Edit
  • Type *.* to ignore all files (or *.jpg for just jpg files, etc.)
1

Watch your trailing slashes too. I found that including images/* in my ignore setting file did not ignore ./images/. When I ran svn status -u it still showed ? images. So, I just changed the ignore setting to just images, no slashes. Ran a status check and that cleared it out.

1

After losing a lot of time looking for how to do this simple activity, I decided to post it was not hard to find a decent explanation.

First let the sample structure

$ svn st ? project/trunk/target ? project/trunk/myfile.x

1 – first configure the editor,in mycase vim export SVN_EDITOR=vim

2 – “svn propedit svn:ignore project/trunk/” will open a new file and you can add your files and subdirectory in us case type “target” save and close file and works

$ svn st ? project/trunk/myfile.x

thanks.

Not the answer you're looking for? Browse other questions tagged or ask your own question.