So di essere in ritardo per la festa, ma ecco la mia risposta.
Come ha detto @Joakim, per ignorare un file, puoi usare qualcosa come sotto.
# Ignore everything
*
# But not these files...
!.gitignore
!someFile.txt
ma se il file si trova nelle directory nidificate, è un po 'difficile scrivere manualmente le regole.
Ad esempio, se vogliamo saltare tutti i file in un gitprogetto, ma non in a.txtcui si trova aDir/anotherDir/someOtherDir/aDir/bDir/cDir. Quindi, la nostra .gitignoresarà qualcosa del genere
# Skip all files
*
# But not `aDir/anotherDir/someOtherDir/aDir/bDir/cDir/a.txt`
!aDir/
aDir/*
!aDir/anotherDir/
aDir/anotherDir/*
!aDir/anotherDir/someOtherDir/
aDir/anotherDir/someOtherDir/*
!aDir/anotherDir/someOtherDir/aDir/
aDir/anotherDir/someOtherDir/aDir/*
!aDir/anotherDir/someOtherDir/aDir/bDir/
aDir/anotherDir/someOtherDir/aDir/bDir/*
!aDir/anotherDir/someOtherDir/aDir/bDir/cDir/
aDir/anotherDir/someOtherDir/aDir/bDir/cDir/*
!aDir/anotherDir/someOtherDir/aDir/bDir/cDir/a.txt
Quanto sopra indicato .gitignore file salterà tutte le directory e i file tranne!aDir/anotherDir/someOtherDir/aDir/bDir/cDir/a.txt
Come avrai notato, è difficile definire quelle regole.
Per risolvere questo ostacolo, ho creato una semplice applicazione console chiamata git-do-not-ignore che genererà le regole per te. Ho ospitato il progetto in github con istruzioni dettagliate.
Esempio di utilizzo
java -jar git-do-not-ignore.jar "aDir/anotherDir/someOtherDir/aDir/bDir/cDir/a.txt"
Produzione
!aDir/
aDir/*
!aDir/anotherDir/
aDir/anotherDir/*
!aDir/anotherDir/someOtherDir/
aDir/anotherDir/someOtherDir/*
!aDir/anotherDir/someOtherDir/aDir/
aDir/anotherDir/someOtherDir/aDir/*
!aDir/anotherDir/someOtherDir/aDir/bDir/
aDir/anotherDir/someOtherDir/aDir/bDir/*
!aDir/anotherDir/someOtherDir/aDir/bDir/cDir/
aDir/anotherDir/someOtherDir/aDir/bDir/cDir/*
!aDir/anotherDir/someOtherDir/aDir/bDir/cDir/a.txt
C'è anche una semplice versione web disponibile qui
Grazie.