Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitignore all files (specific filetype) in a directory and subdirectories [duplicate]

Tags:

git

gitignore

What's the right way to ignore a certain filetype in a certain directory and all subdirectories in it?

Example: ignore all .xml files in master/xyz/ and all subdirectories in master/xyz/.

I'm not sure which of the following two approaches is the right one...

master/xyz/*/*.xml

master/xyz/**/*.xml

Which one should I use?

(I use Git 1.9.1)

like image 863
michbeck Avatar asked Feb 16 '15 10:02

michbeck


People also ask

Does Gitignore apply to subdirectories?

gitignore file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.

How do I ignore a specific file type in git?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

Are Gitignore files cloned?

gitignore file. If a file is added, committed and another commit with the . gitignore is created, the file will still be part of the repository and therefore cloned.


1 Answers

You can add something like this, it will work as of git 1.8.2.1 (documentation here)

A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.

# should work
master/xyz/**/*.xml

The first suggestion you posted won't work as it will not match anything (as it is a literal)

# wont work
master/xyz//.xml
like image 161
acanby Avatar answered Sep 24 '22 19:09

acanby