Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitignore all files of extension in directory

Tags:

git

gitignore

Is there a way to ignore all files of a type in a directory?

** is apparently meaningless to git, so this doesn't work:

/public/static/**/*.js

The idea is to match arbitrary nested folders.

like image 334
Harry Avatar asked May 23 '12 02:05

Harry


People also ask

How do I ignore a file extension 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.

How do I Gitignore a file into a folder?

A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .

Does .gitignore work in 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 .gitignore class file?

The easiest and most common way to ignore files is to use a gitignore file. Simply create a file named . gitignore in the repository's root directory. Then, add names and patterns for any files and directories that should not be added to the repository.


1 Answers

It would appear that the ** syntax is supported by git as of version 1.8.2.1 according to the documentation.

Two consecutive asterisks ("**") in patterns matched against full pathname may have special meaning:

  • A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".

  • A trailing "/**" matches everything inside. For example, "abc/**" matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth.

  • 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.

  • Other consecutive asterisks are considered invalid.

like image 73
joeyhoer Avatar answered Sep 30 '22 03:09

joeyhoer