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?
23 Answers
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 st
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
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.
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.
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.
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:
- svn export a clean copy of your folders (without
.svn
hidden folder) - svn del the local and repository,
- svn ci
- Copy back the folders
- Do svn st and confirm the folders are flagged as '?'
- 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
- With "o" you can open a new line
- Type in all the folder names you want to ignore
- Hit 'esc' key to escape from edit mode
- Type ":wq" then hit Enter to save and quit
The file looks something simply like this:
runtime
cache
attachments
assets
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".
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
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.
"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'.
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.
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.
Solved with Eclipse in the next way:
First of all, do a synchronisation of your folder to the project:
team -> synchronise
In the next view, team view, you can see all resources that you can commit to the SVN server.
So, select the resource folder of the resource that you want to ignore, and then you can ignore it using
team -> add to
svn:ignore
.
After that, in the confirmation window, do select the first option: "ignore by name".
For instance, If I want to ignore the target folder and their .class resources, I'll do synchronise, and in the synchronise view, I'll select the target folder. After that, I'll select
team->add
to svn:ignore
and then I'll confirm the first option in the confirm window.