2012-05-16 7 views
7

Después de leer varias preguntas sobre .gitignore no he encontrado uno que podría responder a mi pregunta:ignorar ciertos archivos en todas las carpetas utilizando un único archivo .gitignore

¿Qué tengo que añadir a .gitignore hacer caso omiso de todos los archivos con una cierta terminación, digamos *.txt en todas las carpetas.

Preferiría tener solo un archivo .gitignore en el nivel superior.

Intenté varias cosas pero ninguna funcionó.

Esto es lo que he probado (.gitignore se añadió al repositorio antes, no se añadió ningún otro archivo):

$ 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") 

Esto es como se esperaba: todos los archivos aparecen desde .gitignore está vacía.

$ 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") 

¿Por qué los archivos content/abc.txt y content/def.txt no aparecen en la lista?

$ git clean -n 
    Would not remove content/ 

Pensé que aparecerían aquí también.

$ 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 

Si el contenido de los archivos/abc.txt y el contenido/def.txt se muestran por clean -n -x pero no por clean -n, creo que son ignorados. Pero entonces, ¿por qué no aparecen en git status --ignored --untracked-files=all?

Respuesta

3

Simplemente agregando *.txt funciona. Compruebe gitignore(5) man page para la explicación del formato gitignore

Si intenta agregar el directorio content, se ignorará todo el archivo *.txt.

$ 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

Parece que la razón porque 'git status --ignored-archivos --untracked = all' no aparece en los archivos de la prueba tiene algo que ver con el "directorio no está realizando un seguimiento"(en realidad se puede No rastreé directorios, solo archivos, pero cuando rastreé un archivo dentro del directorio aparecieron) – KurzedMetal

+0

Eso funcionó. Es extraño, sin embargo, que 'git clean -fx' solo elimine los archivos contenidos luego de que la carpeta contenga un archivo rastreado. De lo contrario, tuve que llamar al comando en la carpeta para eliminar los archivos. – Onur

Cuestiones relacionadas