SVN ignore like .gitignore
Asked Answered
V

4

59

In Git, if I have a project with lots of projects inside, let's suppose, a lot of Java projects, I can just create a .gitignore file in the root and it will "be respected" in the entire repository.

How can I do this for an SVN project?

For example, how can I make an "svn ignore" setup (via cmd line) for a .gitignore like the following?

*.class
*.jar
*.war
*.ear
target/
.classpath
.settings/
.project
.metadata
bin/

The most important part of the question: How can I make it work to new folders inside the root? Example:

I ran svn propset svn:ignore "*.class" . -R in my root and commit. Ok:

root
- folder1/
-- *.class (ignored)
-- other files (ok)
- folder2/
-- *.class (ignored)
-- other files (ok)

Now, I create folder 3. The previous svn:ignore settings will not apply, right? Is there a way to make it so?

Vinegarroon answered 25/6, 2013 at 13:28 Comment(1)
possible duplicate of Recursively ignoring files in the entire source tree in subversionPortugal
P
84

You can use svn:ignore. You generally need to tell SVN to apply special properties to the files:

svn propset svn:ignore "*.jpg" .

(Note the dot at the end of the command.)

For multiple files you can add a newline character.

Type exactly like here with line breaks:

svn propset svn:ignore "file1
file2
file3" dir1

Check that the files are ignored:

svn status --no-ignore

Then commit the code.

And yes, many duplicate questions are already available.

You can refer my favorite svn cheatguide.

You can create a file, svn-ignore.txt, with your ignored files and directories:

*.class
*.jar
*.war
*.ear
 target/
.classpath
.settings/
.project
.metadata
 bin/

Now try the following:

svn propset svn:ignore -RF /root/svn-ignore.txt . [dot for current dir]

-R is for recursive.

Pilatus answered 25/6, 2013 at 16:10 Comment(8)
How would you handle multi-level directories eg app/code/coreDysgraphia
The recursive parameter "-R" should handle any depth of directoriesTumor
From the cheatsheet: Edit a dir's ignores: $ svn propedit svn:ignore your_dir_nameBimetallism
which file does svn propset svn:ignore modify ? i need to know because I would like to actually check it in: #39087666Manifesto
1) does this mean that one need to set the ignore files at every commit or only once and this will apply for the workflow from now on? 2) how can one undo the ignoring of a file?Debag
There is only one problem I have with svn propset. When I use .gitignore I can use it to avoid modifying certain files and choose not to add the ignore file to the git repo itself by never staging it. svn propset values will go into the svn repo on the next commit (if you dont commit specific files) and affect everybody.Brickkiln
What's the context here? Do you type this in the CLI? so you have to specify what you want to ignore every friggin time? How terribly short-sighted SVN is designed, after all these years.Doe
A leading space and trailing slash in folder names in svn-ignore.txt above, such as ` target/`, needed to be removed in my environment. Windows 10, TortoiseSVN 1.12.0.Erdda
A
3

This is what I am doing to emulate .svnignore.

Create a wrapper for svn called ~/bin/svn

#!/bin/bash
case "$1" in
commit|status|apply-ignore)
    if test -f .svnignore ; then
        echo "Apply .svnignore: $(/usr/bin/svn propset svn:ignore -F .svnignore .)"
    fi
    ;;
esac
case "$1" in
apply-ignore) ;;
*) exec /usr/bin/svn "$@" ;;
esac

Then add ~/bin to your path before /usr/bin

PATH=~/bin:$PATH ; export PATH

It applies .svnignore on commit and status commands, and can also manually apply using svn apply-ignore.

Attenborough answered 21/2, 2020 at 12:36 Comment(0)
M
1

If you're using TortoiseSVN as many do, there's an easy way to ignore files. Right you can right anywhere in Windows Explorer to bring up the TortoiseSVN Menu and select Settings, in the General tab click the Edit button under the section labeled Subversion. It will launch Notepad. or default text editor, with file named config.

Locate a line with global-ignores and commented out with # in the file:

### Set global-ignores to a set of whitespace-delimited globs
### which Subversion will ignore in its 'status' output, and
### while importing or adding files and directories.
### '*' matches leading dots, e.g. '*.rej' matches '.foo.rej'.
# global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo __pycache__
#   *.rej *~ #*# .#* .*.swp .DS_Store [Tt]humbs.db

Uncomment the line and add or replace the file patterns with the files you want to ignore and save the file.

global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo __pycache__
    #   *.rej *~ #*# .#* .*.swp .DS_Store [Tt]humbs.db
Medford answered 28/7, 2021 at 14:3 Comment(0)
G
0

I solved this problem a slightly different way. This will only work if you're using a Bash shell and have Perl installed, but that's pretty much every Mac and Linux machine.

Add the following to your .bashrc and .bash_profile files:

alias _ss="svn status | egrep -v '`cat .svnignore|perl -p -e 's/\n/|/'`'"

Don't forget to either restart your terminal or do:

source ~/.bashrc
(or .bash_profile if that's what you used)

Now create a file called .svnignore, and put it in the directory where your repository is checked out.

files/to/ignore
another/file
tmp
node_modules

Now when you run

_ss

in the root directory of your working copy, it will read the .svnignore file and ignore anything in it.

I version the .svnignore file the same way I would version a .gitignore file.

NOTE: This only affects the svn status command, and it won't prevent you from adding/committing ignored files.

Georgie answered 25/3, 2014 at 19:24 Comment(2)
There's no need for such kind of hacks while there's a proper way to do this.Camel
@Camel Maybe you want to use git and svn the same way. For example GitHub has also an svn bridge.Marceline

© 2022 - 2024 — McMap. All rights reserved.