Recursively ignoring files in the entire source tree in subversion

33,150

Solution 1

Edit

The original answer provided below was given prior to Subversion v1.8 which introduced a way to set the default repository level ignore (called svn:global-ignores) without overriding/replacing the svn:ignore property on the root directory and every single subdirectory. Since 1.8, the best way to achieve what you would like is to invoke the following command (credit goes to TManhente):

svn propset svn:global-ignores '*.o' .

On earlier versions (and on later versions), you can still use the approach indicated in the original answer below; however, be aware that this assumes that you are okay with replacing/overwriting the svn:ignore property on each and every subdirectory... this may be fine for a smallish/newish repository but is probably not what you want if you have a large/old repository in which some subdirectories may have independent svn:ignore properties that you do not wish to overwrite.

Original answer

You can use the "-R" or "--recursive" option with "svn propset" as in the following command:

svn propset svn:ignore '*.o' . --recursive

More info

For both cases, you can use the following command for more info about svn propset:

svn help propset

Solution 2

Just an update: Subversion 1.8.0 introduced Inherited Properties and Repository Dictated Configuration (For auto-props and ignores), which can also be used in this case.

You can set the new svn:global-ignores property in the root path. It will "only effect the subtrees rooted at the path on which the property is set".

This new property is set just like svn:ignore:

    svn propset svn:global-ignores '*.o' .

More information is available at the Subversion 1.8.0 Release Notes.

Solution 3

As pointed by @hackmaster.a in a comment, the example given in the accepted answer has the side effect of wiping out all previous svn:ignore settings. Using propedit instead of propset doesn't work neither.

The right way to add multiple files recursively is putting their names in a list separated by new lines in the svn:ignore property set with svn propset svn:ignore "[LIST]" .

For example:

    svn propset svn:ignore -R "*.pkl
    > *.class
    > Thumbs.db
    > data.tmp" .

Of course the >'s are just the shell prompts.

This command will change the svn:ignore properties of the . current directory and of each of its sub-folders recursively.

Share:
33,150
alanquillin
Author by

alanquillin

I have been a software developer for over 15 years with experience in .Net, python, ruby, Java , web development (asp.net/MVC, ruby on rails, php), SQL, and more. My passion is to write code that is fun to use and easy to maintain. I have worked as a software engineer in many different industries from web companies, kiosk manaufacturing, industrial services, media (print, web, tv) and more. I am currently a software developer at Rackspace helping to build and next generation of cloud services. In my spare time I run a media services company (JSI Studios, LLC) with a focus on audio/video recording, mixing and mastering as well as software development. Our companies' goal is to provide end to end services to independent artists and labels.

Updated on July 09, 2022

Comments

  • alanquillin
    alanquillin almost 2 years

    I am not new to Subversion, but I have up till now used Tortoise and never the commadn line. My question is, how do I ignore all files like *.o from the ENTIRE source not just the root.

    For example, if I have the following files: /myfile.o /folder1/myfile2.o /folder1/folder1.1/myfile3.o /folder2/myfile4.o

    If svn propedit svn:ignore "." in the root directory, and add *.o, it will ignore the myfile.o, but does not ignore /folder1/myfile2.o, /folder1/folder1.1/myfile3.o, /folder2/myfile4.o. Is there a way to add *.o in for an entire project (I cannot do it for the entire repository, which I know can be done, because this project is in a repository with many other projects)?

    Please let me know if I need to clarify. Thanks!

  • alanquillin
    alanquillin over 14 years
    Thanks, that worked great! I am still getting the hang of their documentation. As I stated, I have, up til now, solely used tortoise and that gives you nice dialog boxes and explanations :).
  • Junior Mayhé
    Junior Mayhé almost 13 years
    you have also --force svn propset svn:ignore "*.pdb *.db" c:\portal\ --recursive --force
  • hackartisan
    hackartisan about 12 years
    The accepted answer will wipe out all your other svn:ignore settings if you had them. you may then be wanting stackoverflow.com/questions/3086418/…
  • Artem Russakovskii
    Artem Russakovskii about 12 years
    I wanted to second the warning by hackmaster and thank him for the linked solution. FYI, I opted in instead for the global config solution located in ~/.subversion/config
  • Frunsi
    Frunsi almost 11 years
    The comment from hackmaster should be pinned on the top of this thread. An "accepted answer", which contains instructions to wrack your repository (at least some parts of it) is not such a good thing ;)
  • lrkwz
    lrkwz over 9 years
    Using 1.7.4 whipes out all the svn:ignore
  • Michael Aaron Safyan
    Michael Aaron Safyan almost 9 years
    @Frunsi, thanks for bringing this up. This answer had initially been submitted prior to the availability of the alternative, but you're right... I should have clarified my assumption that you don't already have svn:ignore properties on subdirectories that you wish to preserve. I've updated the answer to be more up-to-date and explicit.
  • mgouin
    mgouin over 6 years
    I would really like to know how to set it using auto-props?
  • Luke
    Luke almost 6 years
    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? Imgur
  • TManhente
    TManhente almost 6 years
    @Luke: The reason is that you are calling the svn propset command multiple times. Every time propset is called, it replaces the previous value of the property with the new value you're passing. What you need to do is either add all ignore rules in a single propset call, or use svn propedit instead of propset. Check the command's documentation for more info.
  • Sampgun
    Sampgun about 5 years
    This is awful compared to the .gitignore way, but I managed to do it. Thank you. I really didn't want to manually ignore folders and files from each PC with TortoiseSVN.
  • ionalchemist
    ionalchemist about 2 years
    I'm having trouble figuring out why my directories are not being ignored. I did this, recursively: [Ll]ibrary/ but when I go to commit from my project, this shows up in the list of non-versioned files: Root/Library/... I'm clearly doing something wrong.