2009-12-29 14 views
12

Vorrei solo monitorare certe directory in git in un progetto più grande, in cui la maggior parte delle directory verrà esclusa e solo poche verranno tracciate. Quindi, volevo usare i non-operatori nel mio file .gitignore o escludi, ja?Git non ignorerà una directory

perché sta succedendo questo:

% mkdir wtfgit 
% cd wtfgit 
% git init 
Initialized empty Git repository in /home/foobar/wtfgit/.git/ 
% mkdir iwantthesefiles 
% touch iwantthesefiles/foo 
% mkdir idontwantthesefiles 
% touch idontwantthesefiles/bar 
% vim .gitignore 
% cat .gitignore 
* 
!iwantthesefiles/   
% git add --all 
% git status 
# On branch master 
# 
# Initial commit 
# 
nothing to commit (create/copy files and use "git add" to track) 

Il "non" la sintassi funziona bene per i file nella directory più alta.

% touch baz   
% vim .gitignore 
% cat .gitignore 
* 
!iwantthesefiles/ 
!baz 
% git add --all 
% git status  
# On branch master 
# 
# Initial commit 
# 
# Changes to be committed: 
# (use "git rm --cached <file>..." to unstage) 
# 
# new file: baz 
# 

Come posso ottenere questo per darmi baz e foo come file git tracciati? (In sostanza, come funziona la directory NOT-style globbing funziona a tutti ?! Sembra non farlo.)

Grazie!

risposta

2

Non parlare delle directory nel tuo .gitignore, solo i file. Facendo questo e aggiungendo in modo esplicito le directory che si desidera tenere traccia dovrebbe darvi ciò che si vuole:

 
$ cat > .gitignore << EOF 
* 
!bar 
EOF 
$ git add -f iwantthesefiles 

Questo vi permetterà di git bar pista e tutto nelle iwanthesefiles directory.

0

Git si comporta in questo modo: non ignorerà un file presente nel repository. Inoltre, per escludere le directory, terminare con una barra. Come puoi vedere nel seguente esempio, sono stati tracciati solo iwantthesefiles/baz.

$ cat .gitignore 
*/ 
!iwantthesefiles 
$ git status 
# On branch master 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
#  .gitignore 
#  iwantthesefiles/baz 
nothing added to commit but untracked files present (use "git add" to track) 
$ ls -lhR 
.: 
total 8.0K 
drwxr-xr-x 2 user group 4.0K 2009-12-29 14:24 idonntwantthesefiles 
drwxr-xr-x 2 user group 4.0K 2009-12-29 14:24 iwantthesefiles 

./idonntwantthesefiles: 
total 0 
-rw-r--r-- 1 user group 0 2009-12-29 14:22 bar 
-rw-r--r-- 1 user group 0 2009-12-29 14:24 baz 

./iwantthesefiles: 
total 0 
-rw-r--r-- 1 user group 0 2009-12-29 14:24 baz 
-rw-r--r-- 1 user group 0 2009-12-29 14:19 foo 
$ rm -r * && git reset --hard && ls -lhR 
HEAD is now at 698c66a monkey 
.: 
total 4.0K 
drwxr-xr-x 2 user group 4.0K 2009-12-29 14:25 iwantthesefiles 

./iwantthesefiles: 
total 0 
-rw-r--r-- 1 user group 0 2009-12-29 14:25 foo 

E, per dimostrare che un override di file monitorati .gitignore:

$ mkdir idonntwantthesefiles 
$ touch idonntwantthesefiles/baz 
$ 
git add idonntwantthesefiles/baz 
$ git commit -m 'llama' 
Created commit a62b6d5: llama 
0 files changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 idonntwantthesefiles/baz 
$ echo foobar > idonntwantthesefiles/baz 
$ git status 
# On branch master 
# Changed but not updated: 
# (use "git add <file>..." to update what will be committed) 
# 
#  modified: idonntwantthesefiles/baz 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
#  .gitignore 
no changes added to commit (use "git add" and/or "git commit -a") 
17

Rilanciare un vecchio post, in caso qualcuno inciampa altro su questo:

Se si desidera ignorare tutte le cartelle/file nella directory corrente, utilizzare una barra iniziale (/*/ per le directory o /* per i file); altrimenti Git ignorerà il pattern in modo ricorsivo, il che farà sì che anche i file nelle directory non identificate vengano ignorati ...

Con questo in mente, lo schema !directory/ non cancella le directory bene.

+2

Per quanto mi riguarda, ho dovuto aggiungere due linee:!! 'Script /' e 'script/*' – user151841

14

Per aggiungere con forza le cartelle che vengono ignorati, uso:

git add -f my-ignored-folder 
Problemi correlati