1

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
gerrytan
  • 40,313
  • 9
  • 84
  • 99
  • you can do git clean, and it'll be removed. If it is there, and not added to git, its status should be untracked. – Min Lin Apr 12 '13 at 03:15
  • 1
    @matt junk.txt is a new file added after .gitignore is setup, hence nothing to do with cache as mentioned on that post. I've tried to rm --cached anyway and it gives errors, and the file is still detected as untracked file – gerrytan Apr 12 '13 at 03:17
  • 1
    Can you verify that .gitignore contains what you think it contains? It looks like you're in Windows while typing bash commands, which is probably the source of your trouble. – user229044 Apr 12 '13 at 03:23
  • What does that '+1 ~0 -0 !' part in the prompt mean? That's not what I usually see in my repository. Additionally, repeating those steps exactly as described does ignore the file. – Arafangion Apr 12 '13 at 03:24
  • You are on Windows, I am betting that because you created your .gitignore file in this funny way it is invalid (bad line endings, bad encoding, something like that) – matt Apr 12 '13 at 03:25

1 Answers1

0

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.

Arafangion
  • 11,517
  • 1
  • 40
  • 72
  • 1
    There isn't any quotation mark on .gitignore, but the way I created .gitingore seem to cause file encoding issue -- hence it's not read by git. When I created it using notepad it works as expected. Thanks for the help – gerrytan Apr 12 '13 at 03:33