Lecacy
Lecacy

Reputation: 31

How to make git ignore files without . ("dot") character

For example, I have these files:

sorting
generateData
tmp.c
tmp.txt

I want to ignore two files "sorting" and "generateData".

I tried adding "[^.]+", "[^.]" into .gitignore file but it does not work.

Upvotes: 0

Views: 841

Answers (2)

jthill
jthill

Reputation: 60393

With a little work you can get that effect for any particular repo.

If you put

*
!*.*

at the top of a .gitignore, that will have the effect of accepting all and only files with a dot. This does what you want but also bypasses all lower-precedence files.

So if you put the above at the top of .git/info/exclude it'll have the effect of ignoring everything without a dot and also shutting off your personal excludes (in ~/.config/git/ignore by default). You can kludge around that easily enough, but it'll never be pretty.

Upvotes: 1

Carl Suster
Carl Suster

Reputation: 6066

I recommend reading the manual: man gitignore.

You have the wrong syntax and you actually can't do what you're asking since it's not a regular expression engine. Try adding the specific files you want to ignore instead:

sorting
generateData

Upvotes: 2

Related Questions