Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git ignore multiple matching files

Tags:

git

I try to ignore file in a directory by relative path. E.g. I have several directories in working tree lib/file.f and I want all occurrences of this file to be ignored. I tried

lib/file.f

but this does not work.

like image 864
michael nesterenko Avatar asked Oct 30 '11 19:10

michael nesterenko


People also ask

Can you have multiple git ignore files?

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 .

How do I ignore a few files 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.

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 folder in Gitignore?

If you want to maintain a folder and not the files inside it, just put a ". gitignore" file in the folder with "*" as the content. This file will make Git ignore all content from the repository.


1 Answers

Place

*/lib/file.f

in your .gitignore. This will cause git to ignore any file of the form project/<DIR>/lib/file.f, assuming .gitignore is in the project directory. To make git ignore lib/file.f two directories down, you'd also have to add

*/*/lib/file.f

to the .gitignore, and so on.

Vastly simpler of course, would be to place

*file.f

in .gitignore to block all files named file.f, but your question seems to suggest there is at least one file by that name you wish not to ignore.

like image 78
unutbu Avatar answered Sep 21 '22 20:09

unutbu