I have a .gitignore
file like this:
# no binaries
*/
!*.go/
!.gitignore
I thought */
means to ignore all files in all subdirectories (so every file), !*.go/
means to not-ignore all *.go
files in all subdirectories, and !.gitignore
means to not ignore .gitignore
.
However, the issue I have now is that when I create a new *.go
file in a subdirectory, it's now ignored.
How do I correctly gitignore all compiled binaries, but not ignore *.go
files?
I now have
**/*
!**/*.go
!.gitignore
But it still ignores all *.go files in the ch1 directory. Anyone else have ideas?
This will ignore everything except .go files, and works for subdirectories too:
**/*
!**/*.go
!**/
You may also want to check out this question, which is asking something very similar.
You need to use:
**/*.go
The **
is for ignoring files inside any folder and not only in the current folder.
Allow a later
!/abc/def
to override an earlier/abc
that
appears in the same.gitignore
file to make it easier to expresseverything in /abc directory is ignored, except for ...
.
.gitignore
documentation:Two consecutive asterisks (
**
) in patterns matched against full pathname may have special meaning:
Leading **
A leading **
followed by aslash
means match in all directories.
For example,**/foo
matches file or directoryfoo
anywhere, the same as patternfoo
.**/foo/bar
matches file or directory "bar" anywhere that is directly under directoryfoo
.
Trailing **
A trailing /**
matches everything inside.
For example,abc/**
matches all files inside directoryabc
, relative to the location of the.gitignore
file, with infinite depth.
/**/
A slash followed by two consecutive asterisks then a slash matches zero or more directories.
For example,a/**/b
matchesa/b
,a/x/b
,a/x/y/b
and so on.
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