.gitignore - Ignore everything in a directory except one file

If the file was added in a previous commit before you put it in git ignore, it's possible your .gitignore is not working. I had the same problem few days ago. I solved the problem thanks to this post:

Post int randallkent

I hope this helps you

EDIT:

solution was found here: gitignore directory exception not working


It seems ! only works if the file is in the same folder. A possible workaround would be to nest the same statement till you get to your final file. A bit messy, but it works.

public/typings/*
!public/typings/browser
public/typings/browser/*
!public/typings/browser/ambient
public/typings/browser/ambient/*
!public/typings/browser/ambient/jquery
public/typings/browser/ambient/jquery/*
!public/typings/browser/ambient/jquery/jquery.d.ts

Tags:

Gitignore