Use Git Ignore Check to See Why a File Is Ignored
Having Git issues with your file not being detected? Your file might be git ignored. You can use the git check-ignore command to verify if your file is gitnored. It will tell you also which gitignore if you have multiple and which line.
So let’s say we have this directory structure;
> ls -a
.git
.gitignore
all.json
js
> cd js
> ls -a
.gitignore
foo.js
So we have a git project with a file all.json
and a .gitignore
in the root. We
also have a directory called js
which also has a .gitignore
in it and a file
call foo.js
. Let’s take a peek at the gitignores:
> pwd
/Users/me/git-check
> ls -a
.git
.gitignore
all.json
js
> cat .gitignore
all.json
> cd js
> cat .gitignore
foo.js
So, we can see that in the root all.json
is ignored and in the js
directory
we’re ignoring foo.js. Let’s see what happens when we use git check-ignore
> git check-ignore -v all.json
.gitignore:1:all.json all.json
> git check-ignore -v js/foo.js
js/.gitignore:1:foo.js js/foo.js
The -v
is a verbose flag and gives us the line number and the actual .gitignore
which is useful information to have. This Stackoverflow
answer is a good running commentary from the author who actually implemented the
git check-ignore feature.
Read more about in the git docs