680

How do I ignore files in Subversion?

Also, how do I find files which are not under version control?

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
andyuk
  • 34,840
  • 15
  • 49
  • 52

18 Answers18

766

(This answer has been updated to match SVN 1.8 and 1.9's behaviour)

You have 2 questions:

Marking files as ignored:

By "ignored file" I mean the file won't appear in lists even as "unversioned": your SVN client will pretend the file doesn't exist at all in the filesystem.

Ignored files are specified by a "file pattern". The syntax and format of file patterns is explained in SVN's online documentation: http://svnbook.red-bean.com/nightly/en/svn.advanced.props.special.ignore.html "File Patterns in Subversion".

Subversion, as of version 1.8 (June 2013) and later, supports 3 different ways of specifying file patterns. Here's a summary with examples:

1 - Runtime Configuration Area - global-ignores option:

  • This is a client-side only setting, so your global-ignores list won't be shared by other users, and it applies to all repos you checkout onto your computer.
  • This setting is defined in your Runtime Configuration Area file:
    • Windows (file-based) - C:\Users\{you}\AppData\Roaming\Subversion\config
    • Windows (registry-based) - Software\Tigris.org\Subversion\Config\Miscellany\global-ignores in both HKLM and HKCU.
    • Linux/Unix - ~/.subversion/config

2 - The svn:ignore property, which is set on directories (not files):

  • This is stored within the repo, so other users will have the same ignore files. Similar to how .gitignore works.
  • svn:ignore is applied to directories and is non-recursive or inherited. Any file or immediate subdirectory of the parent directory that matches the File Pattern will be excluded.
  • While SVN 1.8 adds the concept of "inherited properties", the svn:ignore property itself is ignored in non-immediate descendant directories:

    cd ~/myRepoRoot                             # Open an existing repo.
    echo "foo" > "ignoreThis.txt"                # Create a file called "ignoreThis.txt".
    
    svn status                                  # Check to see if the file is ignored or not.
    > ?    ./ignoreThis.txt
    > 1 unversioned file                        # ...it is NOT currently ignored.
    
    svn propset svn:ignore "ignoreThis.txt" .   # Apply the svn:ignore property to the "myRepoRoot" directory.
    svn status
    > 0 unversioned files                       # ...but now the file is ignored!
    
    cd subdirectory                             # now open a subdirectory.
    echo "foo" > "ignoreThis.txt"                # create another file named "ignoreThis.txt".
    
    svn status
    > ?    ./subdirectory/ignoreThis.txt        # ...and is is NOT ignored!
    > 1 unversioned file
    

    (So the file ./subdirectory/ignoreThis is not ignored, even though "ignoreThis.txt" is applied on the . repo root).

  • Therefore, to apply an ignore list recursively you must use svn propset svn:ignore <filePattern> . --recursive.

    • This will create a copy of the property on every subdirectory.
    • If the <filePattern> value is different in a child directory then the child's value completely overrides the parents, so there is no "additive" effect.
    • So if you change the <filePattern> on the root ., then you must change it with --recursive to overwrite it on the child and descendant directories.
  • I note that the command-line syntax is counter-intuitive.

    • I started-off assuming that you would ignore a file in SVN by typing something like svn ignore pathToFileToIgnore.txt however this is not how SVN's ignore feature works.

3- The svn:global-ignores property. Requires SVN 1.8 (June 2013):

  • This is similar to svn:ignore, except it makes use of SVN 1.8's "inherited properties" feature.
  • Compare to svn:ignore, the file pattern is automatically applied in every descendant directory (not just immediate children).
    • This means that is unnecessary to set svn:global-ignores with the --recursive flag, as inherited ignore file patterns are automatically applied as they're inherited.
  • Running the same set of commands as in the previous example, but using svn:global-ignores instead:

    cd ~/myRepoRoot                                    # Open an existing repo
    echo "foo" > "ignoreThis.txt"                       # Create a file called "ignoreThis.txt"
    svn status                                         # Check to see if the file is ignored or not
    > ?    ./ignoreThis.txt
    > 1 unversioned file                               # ...it is NOT currently ignored
    
    svn propset svn:global-ignores "ignoreThis.txt" .
    svn status
    > 0 unversioned files                              # ...but now the file is ignored!
    
    cd subdirectory                                    # now open a subdirectory
    echo "foo" > "ignoreThis.txt"                       # create another file named "ignoreThis.txt"
    svn status
    > 0 unversioned files                              # the file is ignored here too!
    

For TortoiseSVN users:

This whole arrangement was confusing for me, because TortoiseSVN's terminology (as used in their Windows Explorer menu system) was initially misleading to me - I was unsure what the significance of the Ignore menu's "Add recursively", "Add *" and "Add " options. I hope this post explains how the Ignore feature ties-in to the SVN Properties feature. That said, I suggest using the command-line to set ignored files so you get a feel for how it works instead of using the GUI, and only using the GUI to manipulate properties after you're comfortable with the command-line.

Listing files that are ignored:

The command svn status will hide ignored files (that is, files that match an RGA global-ignores pattern, or match an immediate parent directory's svn:ignore pattern or match any ancesor directory's svn:global-ignores pattern.

Use the --no-ignore option to see those files listed. Ignored files have a status of I, then pipe the output to grep to only show lines starting with "I".

The command is:

svn status --no-ignore | grep "^I"

For example:

svn status
> ? foo                             # An unversioned file
> M modifiedFile.txt                # A versioned file that has been modified

svn status --no-ignore
> ? foo                             # An unversioned file
> I ignoreThis.txt                  # A file matching an svn:ignore pattern
> M modifiedFile.txt                # A versioned file that has been modified

svn status --no-ignore | grep "^I"
> I ignoreThis.txt                  # A file matching an svn:ignore pattern

ta-da!

Zulan
  • 20,904
  • 6
  • 41
  • 90
andyuk
  • 34,840
  • 15
  • 49
  • 52
  • 7
    To find ignored files: svn status -u -v --no-ignore |grep "^I"|awk "{print \$2}" – Christian Madsen Sep 15 '10 at 10:32
  • 3
    if you want to ignore file ./FolderA/FolderB/FileToIgnore, do this from your . folder: svn propset svn:ignore "FileToIgnore" FolderA/FolderB/ – jnj Nov 18 '12 at 23:51
  • Thanks. Note that if you use single quotes in your awk programs, you don't need to escape the (commonly used there) dollar sign. Just a nit. :-D – JJC May 23 '13 at 23:30
  • 10
    if you are ssh'ing `svn propedit svn:ignore .` and no text editor is configured you'll get an error message saying _svn: E205007: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found_ instead of getting an editor opened. So just specify _--editor-cmd nano_ like this `svn propedit svn:ignore . --editor-cmd nano` – Jonathan Morales Vélez Jul 31 '13 at 23:01
  • This command should be executed inside the containing-files-to-ignore folder? I mean... oh... `.` is a folder to propset on? – Nakilon Sep 26 '13 at 18:33
  • @Nakilon yes. You can specify the folder, and . is the current folder – SgtPooki Mar 25 '14 at 13:14
  • 12
    You can also ignore files with a specific filename in all subfolders using the "--recursive" argument. i.e. **svn propset svn:ignore "*.jpg" . --recursive** – Templar Apr 02 '14 at 19:20
  • 2
    A simpler alternative to awk is grep : `svn status | grep '^?'` – Johnride Jun 30 '14 at 21:48
  • Note that in Windows, the first command may fail depending on what files are in the current directory with `(filename) is not under version control`. In this case you must use the second command instead to edit your ignore list. You may need to set your editor first with e.g. `set SVN_EDITOR=notepad` – D Coetzee Jul 31 '14 at 18:13
  • 1
    `EDITOR=vi svn propedit svn:ignore .` solves any doubt – fiorentinoing Jan 24 '17 at 11:22
  • @Johnride you mean `-v`, don't you? – Narcolessico Jan 09 '18 at 13:43
  • 1
    Might be worth mentioning that svn propset overrides any previous svn propset. – Ben Aveling Feb 25 '18 at 12:00
  • I've add `bin` `debug` `obj` to `svn:global-ignores` but after that, when i `svn propget svn:global-ignores` it only return `obj` (the last one), how can I ignore multiple files/folders? – Luke Jun 20 '18 at 02:47
  • By far the best answer. – Alfonso Nishikawa Dec 28 '18 at 13:24
  • awesome answer :) – Daniele Jan 24 '19 at 11:51
  • I sometimes prefer the `global-ignores` method over `svn propset svn:ignore` because the later will mark the directory as modified (wich invites you to push the property to everyone, which is not always what you want). – Gabriel Devillers May 20 '21 at 06:54
93

Use the following command to create a list not under version control files.

svn status | grep "^\?" | awk "{print \$2}" > ignoring.txt

Then edit the file to leave just the files you want actually to ignore. Then use this one to ignore the files listed in the file:

svn propset svn:ignore -F ignoring.txt .

Note the dot at the end of the line. It tells SVN that the property is being set on the current directory.

Delete the file:

rm ignoring.txt

Finally commit,

svn ci --message "ignoring some files"

You can then check which files are ignored via:

svn proplist -v
icc97
  • 8,746
  • 6
  • 60
  • 75
ulitosCoder
  • 1,733
  • 15
  • 19
  • 2
    Nice. A minor improvement is `svn status | awk "/^?/ {print \$2}" > ignoring.txt`. – Dirk Eddelbuettel Aug 22 '14 at 14:48
  • 4
    why delete the file? keep it in repo if u need to re create/add/remove – tgkprog Mar 14 '15 at 16:28
  • Note this solution will not ignore files in subdirectories (even if they show up in ignoring.txt). – shaneb Apr 24 '17 at 20:02
  • Would that keep existing ignores? If not, how to do it in one command (i.e. --no-ignores and keep also lines preceded by I )? – a1an Jun 19 '17 at 13:49
  • This would overwrite your current ignores, try: `svn pg svn:ignore . >> ignore.txt` after the first command to append the current ignores to the file. – ulitosCoder Jun 22 '17 at 15:24
  • @tgkprog it's just a one time use to load the files into the properties. So the file is not guaranteed to contain the same as what's in the properties. So it makes sense to delete it and get people to run `svn proplist -v` to check which files actually are ignored. – icc97 Aug 30 '17 at 13:37
64

.gitignore like approach

You can ignore a file or directory like .gitignore. Just create a text file of list of directories/files you want to ignore and run the code below:

svn propset svn:ignore -F ignorelist.txt .

OR if you don't want to use a text file, you can do it like this:

svn propset svn:ignore "first
 second
 third" .

Source: Karsten's Blog - Set svn:ignore for multiple files from command line

Community
  • 1
  • 1
Adrian Enriquez
  • 7,236
  • 7
  • 39
  • 62
  • 2
    Note that if you later modify your ignore file, you do need to rerun the `svn:ignore` command (see https://stackoverflow.com/a/58380306/189518) – Sensei James Oct 18 '19 at 20:02
51

If you are using TortoiseSVN, right-click on a file and then select TortoiseSVN / Add to ignore list. This will add the file/wildcard to the svn:ignore property.

svn:ignore will be checked when you are checking in files, and matching files will be ignored. I have the following ignore list for a Visual Studio .NET project:

bin obj
*.exe
*.dll
_ReSharper
*.pdb
*.suo

You can find this list in the context menu at TortoiseSVN / Properties.

Rory O'Kane
  • 25,436
  • 11
  • 86
  • 123
artur02
  • 4,361
  • 1
  • 19
  • 15
37

As nobody seems to have mentioned it...

svn propedit svn:ignore .

Then edit the contents of the file to specify the patterns to ignore, exit the editor and you're all done.

Yorick
  • 684
  • 6
  • 8
  • 4
    This answer was useful. In my case I needed to change "." to the sub-directory of the file I wanted to ignore and just specify the file pattern. Also, the first time, I needed run this (I'm on Mac): export SVN_EDITOR="nano" – Elijah Lofgren Nov 16 '17 at 04:31
22

I found the article .svnignore Example for Java.

Example: .svnignore for Ruby on Rails,

/log

/public/*.JPEG
/public/*.jpeg
/public/*.png
/public/*.gif

*.*~

And after that:

svn propset svn:ignore -F .svnignore .

Examples for .gitignore. You can use for your .svnignore

https://github.com/github/gitignore

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
d.danailov
  • 8,760
  • 4
  • 47
  • 35
  • 1
    i did as u said... but when i run svn status. it still shows the ignored files with "?" – Harshit Gupta Mar 27 '14 at 01:11
  • I never checked with svn status, but with svn add * and after that svn commit, ignoring files is doesn't commit. – d.danailov Mar 27 '14 at 07:48
  • if a file "a.txt" already in version control, then the ignore is done by the command like "svn propset svn:ignore -F .svnignore a.txt" ? is it correct ? – errakeshpd Dec 30 '14 at 04:13
  • If you add "a.txt" in your .svnignore file, I am not sure, but command should be properly. – d.danailov Dec 30 '14 at 06:55
10

When using propedit make sure not have any trailing spaces as that will cause the file to be excluded from the ignore list.

These are inserted automatically if you've use tab-autocomplete on linux to create the file to begin with:

svn propset svn:ignore 'file1
file2' .
Kenneth
  • 1,147
  • 1
  • 12
  • 25
8

Also, if you use Tortoise SVN you can do this:

  1. In context menu select "TortoiseSVN", then "Properties"
  2. In appeared window click "New", then "Advanced"
  3. In appeared window opposite to "Property name" select or type "svn:ignore", opposite to "Property value" type desired file name or folder name or file mask (in my case it was "*/target"), click "Apply property recursively"
  4. Ok. Ok.
  5. Commit
bzlm
  • 9,198
  • 5
  • 59
  • 86
msangel
  • 8,829
  • 3
  • 43
  • 64
8

Another solution is:

svn st | awk '/^?/{print $2}' > svnignore.txt && svn propget svn:ignore >> svnignore.txt && svn propset svn:ignore -F svnignore.txt . && rm svnignore.txt

or line by line

svn st | awk '/^?/{print $2}' > svnignore.txt 
svn propget svn:ignore >> svnignore.txt 
svn propset svn:ignore -F svnignore.txt . 
rm svnignore.txt

What it does:

  1. Gets the status files from the svn
  2. Saves all files with ? to the file "svnignore.txt"
  3. Gets the already ignored files and appends them to the file "svnignore.txt"
  4. Tells the svn to ignore the files in "svnignore.txt"
  5. Removes the file
Jim
  • 2,817
  • 1
  • 17
  • 29
bkbilly
  • 193
  • 1
  • 12
6
  1. cd ~/.subversion
  2. open config
  3. find the line like 'global-ignores'
  4. set ignore file type like this: global-ignores = *.o *.lo *.la *.al .libs *.so .so.[0-9] *.pyc *.pyo 88 *.rej ~ ## .#* .*.swp .DS_Store node_modules output
范陆离
  • 71
  • 1
  • 3
  • Thank you, your answer is the only one that mentions the `config` file. – Henrique de Sousa May 25 '17 at 09:32
  • This answer mentions it as well @HenriquedeSousa https://stackoverflow.com/a/86052/7724 and also explains that it is a local client-only way of ignoring files. – bzlm Sep 14 '17 at 17:31
5

A more readable version of bkbilly's answer:

svn st | awk '/^?/{print $2}' > svnignore.txt
svn propget svn:ignore >> svnignore.txt
svn propset svn:ignore -F svnignore.txt .
rm svnignore.txt

What it does:

  1. Gets the status files from the svn
  2. Saves all files with ? to the file "svnignore.txt"
  3. Gets the already ignored files and appends them to the file "svnignore.txt"
  4. Tells the svn to ignore the files in "svnignore.txt"
  5. Removes the file
bzlm
  • 9,198
  • 5
  • 59
  • 86
LivingDust
  • 97
  • 1
  • 6
  • I like bkbilly's answer, but this version breaks each line to make it more readable, and removes the && which in my tests did nothing, since the first line always creates the temporary file, and this same temporary file always gets into the ignore list. – LivingDust Dec 01 '16 at 01:09
  • An edit proposition would have more appropriate in this case. Appreciate the effort ! – Jim Dec 01 '16 at 02:03
  • I didn't have enough reputation yet to suggest an edit. but I don't want to ruin a good protocol. Is there an simple README on guidelines for when to it is better to suggest and edit rather than post a new answer etc? – LivingDust Dec 12 '16 at 17:18
  • 1
    If your answer is exactly the same as the one posted a year and a half ago, it's pretty straight forward. You even copied the "*What it does*" explanation. – Jim Dec 12 '16 at 19:11
4

What worked for me (I am using TortoiseSVN v1.13.1):

How do I ignore files in Subversion?

1.In File Explorer, right-click on SVN project folder-name
2.Click on "SVN Commit..."
3.A "commit" window will appear
4.Right-click on the folder/file that you want to ignore
5.Click on "Add to ignore list"
6.Select the folder/file name you want to ignore

  • There's a few choices(4 for me), if you choose only the folder/file name, it will be added to svn:ignore list
  • if you choose the folder/file name, with (recursively), it will be added to svn:global-ignores. This is what i normally choose, as this change is inherited automatically by all sub-directories. enter image description here

7.Commit the "property change" to SVN

Also, how do I find files which are not under version control?

After Step 3 above, click on "Show unversioned files" as follows:
enter image description here

jumping_monkey
  • 2,284
  • 14
  • 25
3

Adding a directory to subversion, and ignoring the directory contents

svn propset svn:ignore '\*.*' .

or

svn propset svn:ignore '*' .
nbro
  • 12,226
  • 19
  • 85
  • 163
Al Conrad
  • 1,180
  • 14
  • 11
3

svn status will tell you which files are not in SVN, as well as what's changed.

Look at the SVN properties for the ignore property.

For all things SVN, the Red Book is required reading.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
DGM
  • 25,680
  • 6
  • 56
  • 79
3

You can also set a global ignore pattern in SVN's configuration file.

petr k.
  • 7,830
  • 6
  • 39
  • 52
2

SVN ignore is easy to manage in TortoiseSVN. Open TortoiseSVN and right-click on file menu then select Add to ignore list.

This will add the files in the svn:ignore property. When we checking in the files then those file which is matched with svn:ignore that will be ignored and will not commit.

In Visual Studio project we have added following files to ignore:

bin obj
*.exe
*.dll
*.pdb
*.suo

We are managing source code on SVN of Comparetrap using this method successfully

Slack
  • 109
  • 1
  • 3
2

Use the command svn status on your working copy to show the status of files, files that are not yet under version control (and not ignored) will have a question mark next to them.

As for ignoring files you need to edit the svn:ignore property, read the chapter Ignoring Unversioned Items in the svnbook at http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.ignore.html. The book also describes more about using svn status.

Andreas Holstenson
  • 1,408
  • 9
  • 7
0
  1. open you use JetBrains Product(i.e. Pycharm)
  2. then click the 'commit' button on the top toolbar or use shortcut 'ctrl + k' screenshot_toolbar
  3. on the commit interface, move your unwanted files to another change list as follows. screenshot_commit_change
  4. next time you can only commit default change list.
G. Googol
  • 1
  • 1
  • 1