I have a problem to get .gitignore to do what I want. My folder structure looks like so:
assets
├── img
| ├── thousands
| ├── of
| ├── folders
| ├── KEEP_SOMETHING_IN_THIS_FOLDER
| | ├── another
| | ├── thousands
| | ├── of
| | ├── folders
| | ├── KEEP_THIS_FILE_1.jpg
| | ├── KEEP_THIS_FILE_2.jpg
| | ├── KEEP_THIS_FILE_3.jpg
I try to keep the three jpgs. I tried
/assets/img/*
!/assets/img/KEEP_SOMETHING_IN_THIS_FOLDER/
/assets/img/KEEP_SOMETHING_IN_THIS_FOLDER/*/
!/assets/img/KEEP_SOMETHING_IN_THIS_FOLDER/KEEP_THIS_FILE_*.jpg
There are several locations where Git looks for ignore files. Besides looking in the root folder of a Git project, Git also checks if there is a . gitignore in every subdirectory. This way you can ignore files on a finer grained level if different folders need different rules.
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.
To remove a file from an Ignore List in Solution Explorer, context-click the file and select Manage Files > Remove from Ignore List.
You need to create .gitignore file in specified folder. In "KEEP_SOMETHING_IN_THIS_FOLDER" in your case. And write this lines:
/**
/*.jpg
!not_ignore.jpg
At first commit this .gitignore
file and then try commit your files.
But if your files already has been staged (tracked), try git rm --cached <filePath>
these files.
You were close:
/assets/img/*
!/assets/img/KEEP_SOMETHING_IN_THIS_FOLDER/
# changed this:
# /assets/img/KEEP_SOMETHING_IN_THIS_FOLDER/*/
# to:
# /assets/img/KEEP_SOMETHING_IN_THIS_FOLDER/*
/assets/img/KEEP_SOMETHING_IN_THIS_FOLDER/*
!/assets/img/KEEP_SOMETHING_IN_THIS_FOLDER/KEEP_THIS_FILE_*.jpg
You don't need the trailing slash on the ignore for the child folder (the 3rd line).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With