2012-05-16 9 views
7

Dopo aver letto diverse domande circa .gitignore ho trovato nessuno che potesse rispondere alla mia domanda:ignorare alcuni file in tutte le cartelle utilizzando un unico file .gitignore

Cosa devo aggiungere .gitignore di ignorare tutti i file con un certo finale, diciamo *.txt in tutte le cartelle.

Preferirei avere un solo file alla .gitignore livello superiore.

Ho provato diverse cose ma nessuna ha funzionato.

Questo è quello che ho provato (.gitignore è stato aggiunto al repository prima, è stato aggiunto nessun altro file):

$ ls 
    abc.txt content 

    $ ls content/ 
    abc.txt def.other def.txt 

    $ echo "" > .gitignore 


    $ git status --ignored --untracked-files=all 
    # On branch master 
    # Changes not staged for commit: 
    # (use "git add <file>..." to update what will be committed) 
    # (use "git checkout -- <file>..." to discard changes in working directory) 
    # 
    #  modified: .gitignore 
    # 
    # Untracked files: 
    # (use "git add <file>..." to include in what will be committed) 
    # 
    #  abc.txt 
    #  content/abc.txt 
    #  content/def.other 
    #  content/def.txt 
    no changes added to commit (use "git add" and/or "git commit -a") 

Questo è come previsto: tutti i file vengono visualizzati in quanto .gitignore è vuoto.

$ echo "*.txt" > .gitignore 

    $ git status --ignored --untracked-files=all 
    # On branch master 
    # Changes not staged for commit: 
    # (use "git add <file>..." to update what will be committed) 
    # (use "git checkout -- <file>..." to discard changes in working directory) 
    # 
    #  modified: .gitignore 
    # 
    # Untracked files: 
    # (use "git add <file>..." to include in what will be committed) 
    # 
    #  content/def.other 
    # Ignored files: 
    # (use "git add -f <file>..." to include in what will be committed) 
    # 
    #  abc.txt 
    no changes added to commit (use "git add" and/or "git commit -a") 

Perché non i file contenuti/abc.txt e contenuti/def.txt compare nella lista?

$ git clean -n 
    Would not remove content/ 

ho pensato che sarebbe presentarsi anche qui.

$ echo "" > .gitignore 

    $ git clean -n 
    Would remove abc.txt 
    Would not remove content/ 

    $ cd content 

    $ git clean -n -x 
    Would remove def.other 

    $ git clean -n -x 
    Would remove abc.txt 
    Would remove def.other 
    Would remove def.txt 

Se i file di contenuto/abc.txt e contenuti/def.txt sono mostrati da clean -n -x ma non da clean -n, penso che siano ignorati. Ma allora perché non si presentano in git status --ignored --untracked-files=all?

risposta

3

Basta aggiungere *.txt funziona. Controllare gitignore(5) man page per la spiegazione del formato gitignore

Se si tenta di aggiungere la directory content, tutto il file *.txt verrà ignorato.

$ echo "*.txt" > .gitignore 

$ git add content 

$ git status --ignored --untracked-files=all 
# On branch master 
# 
# Initial commit 
# 
# Changes to be committed: 
# (use "git rm --cached <file>..." to unstage) 
# 
#  new file: content/def.other 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
#  .gitignore 
# Ignored files: 
# (use "git add -f <file>..." to include in what will be committed) 
# 
#  abc.txt 
#  content/abc.txt 
#  content/def.txt 
+1

Sembra che la ragione perché 'git status --ignored --untracked-files = all' non mostra i file nel tuo test ha qualcosa a che fare con la "directory non monitorato"(in realtà si può 't track directory, solo file, ma quando ho rintracciato un file all'interno della directory che hanno mostrato) – KurzedMetal

+0

Che ha funzionato. Strano però che 'git clean -fx' rimuova solo i file nel contenuto dopo che la cartella conteneva un file tracciato. Altrimenti ho dovuto chiamare il comando nella cartella stessa per rimuovere i file! – Onur

Problemi correlati