I know there is a lot of questions like this, but no one solved my problem. I want something very simple - ignore all files and folders under specific folder except one file. This is what I try:
#Ignore
public/typings/*
#Allow
!public/typings/browser/ambient/jquery/jquery.d.ts
...but the file is still ignored.
Any suggestions?
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 .
gitignore file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.
You want to use /* instead of * or */ in most cases The above code would ignore all files except for . gitignore , README.md , folder/a/file. txt , folder/a/b1/ and folder/a/b2/ and everything contained in those last two folders.
Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.
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
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
I've been struggling a lot with this subject, let me share a procedure that worked for me:
1) Add the top level folder "abc/" to your .gitignore 2) Let's say that in "abc/" you have also "def/" and "jkl/" folders. If you want to keep the contents of "jkl/" you can just do:
git add -f jkl/*.php
Ok! Now everything inside "jkl/" with .php extension will be tracked by git, even in the next commits, without any headaches!
I've found this to be the right solution for my case, because I was really going insane trying to understand how gitignore does scan files and directories.
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