Pregunta

I can't seem to work out why my .gitignore isn't ignoring a simple text file. I have read the manual and I think I've done all required steps.

Firstly I created a new repo like this:

C:\> mkdir test
C:\> cd test
C:\test> git init

Then I created and comitted a .gitignore which ignores a file called junk.txt

C:\test [master]> touch .gitignore
C:\test [master +1 ~0 -0 !]> echo 'junk.txt' >> .gitignore
C:\test [master +1 ~0 -0 !]> git add .gitignore
C:\test [master +1 ~0 -0]> git commit -m 'ignoring junk.txt'

By now I would assume if I have a file called junk.txt git would ignore it. But how come it's still saying that as an untracked file?

C:\test [master]> touch junk.txt
C:\test [master +1 ~0 -0 !]> git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       junk.txt

I'm using msysgit

C:\test [master +1 ~0 -0 !]> git --version
git version 1.8.0.msysgit.0
¿Fue útil?

Solución

Gerrytan, you are using bash syntax on a system that does not use bash syntax.

Specifically, when you do the following:

echo 'junk.txt' >> .gitignore

You have told git to ignore the file 'junk.txt' including the quotation marks.

If you had used bash, or any sh-compatible shell, then that command would have told git to ignore 'junk.txt' excluding the quotation marks, because in those shells, the quotation marks indicate the word boundaries, but they have no special meaning in cmd.exe (The standard command line in windows).

I suggest you open .gitignore in an editor and take a look at the entry.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top