Unignore specific Files in Subdirectory with .gitignore

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

Tags:

Git

Gitignore