SVN: Ignore some directories recursively
Asked Answered
N

14

110

I don't want any directory named build or dist to go into my SVN no matter how deep in the tree it is.

Is this possible? In git I just put

build
dist

in my .gitignore at the root and it recursively ignores. How do I do this with svn? Please don't tell me to do a propset on every parent dir...

Nichellenichol answered 9/1, 2010 at 23:12 Comment(1)
Check this answer for a native solution if you're using Subversion 1.8.Fulcrum
W
63

As of subversion 1.8, there is now the svn:global-ignores property which works like svn:ignore but recursively (so set this on your top-level directory)

Wollongong answered 10/2, 2015 at 7:11 Comment(5)
I'm a tad confused - there's global-ignores in the ~/.subversion/config file, but also the inheritable svn:global-ignores property set on a directory in an SVN repo, as well as svn:ignore - can you provide a summary of these different options and how they compare? How does the --recursive flag affect them too?Lavelle
I've done my own research and published my findings in this QA answer: https://mcmap.net/q/47599/-how-do-i-ignore-files-in-subversionLavelle
[I've tried but failed, the obj folder still showed up] (#50960688), can you help me to have a look on it?Neb
Can I say "build/*" go ignore everything below build within every build folder?Inconvenient
This won't ignore folder by name recursively on svn version 1.14.0 (r1876290).Radie
S
44

svn propset takes --recursive as an option, so you can do this, with two downsides:

  1. you have to check out the entire repository (or at least all directories therein), and
  2. you have to remember to set the svn:ignore property whenever you add a new directory
Strangeness answered 10/1, 2010 at 17:54 Comment(0)
E
17

This works for me:

 svn propset --recursive svn:ignore *.zip <dir_tree_with_no_zips>
Edmanda answered 9/2, 2012 at 12:53 Comment(1)
Thanks for this, works great...By the way the only way I found to ignore both *.txt and *.pdf was to put those patterns in a file and then use the 'svn propset --file' optionUbana
T
15

add to your ~/.subversion/config or /etc/subversion/config file:

[miscellany]
global-ignores = build dist
Twohanded answered 9/1, 2010 at 23:19 Comment(3)
I'd rather do it per-repo if I canNichellenichol
hmm not sure if there's an easy way to do it per-repo, a pre-commit hook could reject certain patterns, but it's not a complete solution. svn:ignore on each parent dir works, but not recursively. you could swap out your config file with a script when working on different repos, but that's an extra step.Twohanded
What does build dist mean?Tamatave
B
10

It is possible to ignore build and dist dirs by removing the directories from version control. The trick is to use the --keep-local option to leave the directory in the working copy. For example:

svn rm dist --keep-local
svn ci -m'removed build directory from version control'

The directory will no longer be tracked by subversion but it will still be there in your working copy to hold compiler output, etc.

cheers, joe

Boudreaux answered 24/3, 2011 at 20:20 Comment(1)
This solution looks similar to git ignore.Lamppost
H
7

In subversion 1.8 over, it is possible to set global-ignores for current repository.

svn propset svn:global-ignores build .
svn propset svn:global-ignores dist .

Also you can create a folder named .svnignore, and write conditions.

build
dist

remember one condition per line, setting build/* or dist/debug is in vain. Then do the command:

svn propset svn:global-ignores -F .svnignore .
Hengelo answered 13/11, 2015 at 1:20 Comment(1)
works flawlessly! just run the first command on newly checked out repo.Keddah
A
6

For example the folder structure:

Project/
Project/dist/

cd Project
svn propset svn:ignore '*' dist/
svn ci -m "content of dist ignored"

It's good to do a svn delete of dist content before the ignore command, so for branches dist will be empty.

Worked for me, tested today. Here is the page explaining it a bit

Aeolotropic answered 15/8, 2012 at 9:47 Comment(0)
M
5

In order to ignore all such files in all repositories, you could add a global-ignores to your per-user configuration file.

On Unix-like systems, this area appears as a directory named .subversion in the user's home directory. On Win32 systems, Subversion creates a folder named Subversion, typically inside the Application Data area of the user's profile directory

See Configuration Options

Unfortunately, there's no per-repository option to do this. It's basically per-user, or per-directory, so the multiple svn:ignores is probably the way to go, as annoying as it can be.

Mouth answered 9/1, 2010 at 23:18 Comment(2)
I'd rather do it per-repo if i canNichellenichol
Oh, then you're out of luck. As @Kevin Reid says - you've got per-directory or per-user.Mouth
A
5

You first have to move to the top folder of your working copy and create a file there (say .svnignore) where you should place all the patterns that you want to be ignored, for example (for an Android project):

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

Then you run the following command (remember that you must be at the top folder of your working copy):

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

This will only work for folders and files that are not yet under version control. If you want a folder (or file) that is being versioned to start being ignored as well, remove it from version control by running the command:

svn rm --keep-local <path>

Got all this from this great article that explains it all: http://superchlorine.com/2013/08/getting-svn-to-ignore-files-and-directories/

Adjectival answered 14/10, 2014 at 22:51 Comment(1)
This was immensely helpful. This is the best way I've found to get git-like ignore behavior in svn. Thanks very much.Undercool
G
2

Create a file and add your ignores into it

ingore-list:

file1 
directory1
file2
etc...

then apply the following command

for n in directory; do svn propset svn:ignore -F ignore-list $n; done

directory is name of your directory, you can sub categorize as well directory/sub-directory. Or use * to note current directory you are under.

This is assuming you are using bash as your shell

Ginger answered 24/1, 2013 at 7:2 Comment(2)
What is the $n here?Tamatave
@igor Ganapolsky - The $n is the variable of the for loop. It will be set as the index for the sequence you are looping into; in this case the directory as specified by "directory" in the above example.Ginger
M
2
svn propset --recursive svn:ignore svn_ignore_rules .

where svn_ignore_rules is a file containing the ignore rules -- one per line

Of course you have to re-run it every time you add a new directory to your repo

svn_ignore_rules can also be considered to be checked into the repo, to be re-useable by other users having write access to the repo

Memorialist answered 16/3, 2013 at 23:30 Comment(0)
D
1
cd parent_dir #the directory containing folder to be ignored recursively
svn propedit svn:ignore . #will open up svn-prop.tmp
enlist folder(s)
^X
Y
commit -m 'ignore targeted direcoty'
Dekker answered 26/3, 2013 at 6:56 Comment(1)
helped me, I had problem with setting folder pattern, SVN was complianing that folder not in repo, set EDITOR=notepad, svn propedit svn:ignore .worked well...Brigidbrigida
G
0

One way would be to add some kind of check to either the pre- or post- commit hook but it's note straight forward if you don't own the repo server.

Gandy answered 10/3, 2011 at 12:27 Comment(0)
E
0

Since there seems to be no solution for this probably common problem, i would like to share our solution. As the others already made clear, you can either use the svn:ignore property, this applies to a single directory (and therefore not for new ones), or you use global-ignores which applies to a single user (but doesn't belong to the repository).

To make life a bit easier i created a reg file named Settings.Svn.reg and added it to the root of the repository. Now everybody can doublecklick this regfile once, and has the settings done.

REGEDIT4

[HKEY_CURRENT_USER\Software\Tigris.org\Subversion\Config\miscellany]
"global-ignores"="obj *.suo *.bak *.pdb *.user *.Cache*"

I would really appreciate a solution within the SVN repository, so if somebody knows, would you care to share it?

Empathy answered 16/11, 2011 at 10:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.