Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore exclude files in directory but not certain directories

Tags:

git

gitignore

application/cache/* application/cache/folder/* application/cache/folder/onemorefolder/* 

This doesn't seem to be working. When I clone the project, there is no "application/cache" folder or "application/cache/folder" folder, etc...

I'd like if files in the cache folders weren't cached but folders were, so that the folders permissions transfer and exist.

like image 257
Matthew Avatar asked Apr 08 '11 20:04

Matthew


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.

Does Gitignore need to be in every 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 .


1 Answers

Git doesn't track folders, only files, so if you ignore everything in a folder, Git won't have anything to track. You can add a .gitignore file to each directory (application/cache, application/cache/folder, application/cache/folder/onemorefolder/) with the following contents:

* !.gitignore 

Then, you can add those directories, and only the .gitignore file in each directory will get added -- but this means the directories will now be tracked (i.e., created when cloning).

like image 93
mipadi Avatar answered Oct 15 '22 06:10

mipadi