Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git ignore subfolders but not the files in a folder

Tags:

git

gitignore

I've been looking around and just could not find the same scenario that I have. I have:

--public       |--img            |--logo (folder)            |--post_image (folder)            |--banner.jpg            |--icon.ico            |--image1.jpg            |-........etc 

I need to ignore the logo and post_image folders, but I want to keep every file that is inside img folder. How would I go about it?

Right now I have **/public/img but I feel is not the right approach!

like image 225
Cristian Avatar asked Jan 27 '16 06:01

Cristian


People also ask

How do I ignore files in a folder in Git?

Personal Ignore Rules Patterns that are specific to your local repository and should not be distributed to other repositories should be set in the . git/info/exclude file. For example, you can use this file to ignore generated files from your personal project tools.

How do I not ignore a specific file in Git?

Git ignore patterns An asterisk is a wildcard that matches zero or more characters. Prepending an exclamation mark to a pattern negates it. If a file matches a pattern, but also matches a negating pattern defined later in the file, it will not be ignored.

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 .


Video Answer


2 Answers

I found this to be simpler (at least in the case there are many subfolders):

public/img/*/ 

This will exclude all subfolders in public/img/, but will not exclude the files in this folder.

like image 114
Lorenz Meyer Avatar answered Oct 05 '22 22:10

Lorenz Meyer


You can put a .gitignore file into any child directory, it doesn't have to be at the root. In your case, a .gitignore file in the public/img directory with the content:

logo post_image 

would do the job.

For another approaches, you might want to look at:

  • gitignore all files of extension in directory
  • Git-ignore certain files in sub-directories, but not all
like image 22
reto Avatar answered Oct 05 '22 22:10

reto