2

I am trying to exclude all files except those I need with the following .gitignore config:

*.* # Ignore all files
*~  # Ignore temp files
\#* # Ignore temp files

!.gitignore
!*.conf
!**/*.conf

However, file ./postgresql/9.3/warm-standby/postgresql.conf is not shown when I execute git status. How can I fix my .gitignore?

Git version is 2.1.4

Kirill Dubovikov
  • 1,457
  • 2
  • 21
  • 41

1 Answers1

4

First of all: credit to @EtanReisner for carefully looking into this and @RetoAebersold for providing the correct link

The problem is that with the following statement (not part of your .gitignore), you blacklist both files and directories:

*

Now if you use *.* like you did, that's normally not a problem, because most directories don't contain a dot (.). Yours however does:

*           .*
postgresql/9.3

So what happens is that all directories are blacklisted. In order to enable adding files in directories, you first need to whitelist these directories. You can do this with the oneliner:

!*.*/

In other words, whitelist everything that ends with a slash.

And now you can whitelist the files as well:

!*.conf

Note that whitelisting !**/*.conf is not necessary (It is probably not even allowed, especially since two consecutive asterisks ** were only enabled in git 1.8.*).

A better configuration file thus reads:

*.* # Ignore all files
*~  # Ignore temp files
\#* # Ignore temp files
!*/
!*.*/

!.gitignore
!*.conf
Community
  • 1
  • 1
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
  • Those suggestions work if I add `**/*` to my `.gitignore`, `*.*` seems to exclude only files that are in the current directory. It would be nice to update the answer – Kirill Dubovikov May 20 '15 at 07:27
  • Normally `*.*` will disable *all* files/directories with a dot. Can you elaborate a bit more? – Willem Van Onsem May 20 '15 at 13:57
  • 1
    I have lots of files that need to be excluded in subdirectories. `*.*` seems not to exclude them, so `**/*` or `**/*.*` is needed for it to work recursively. – Kirill Dubovikov May 21 '15 at 07:52