git still shows files as untracked despite .gitign

2019-03-28 00:20发布

I'm not sure what I'm doing wrong in this case with my .gitignore file, but these files keep showing up.

Background

I'm using Jekyll to build a blog. Jekyll generates _site and .sass-cache directories when it begins serving.

I previously committed these directories before realizing I wanted to ignore them.

To be overly cautious, I added all of the following lines to my .gitignore:

##Jekyll
/_site/
_site/
_site
/.sass-cache/
.sass-cache/
.sass-cache

Since I knew I'd committed these files previously, I:

  • Committed the updated .gitignore file.
  • did a git rm -r --cached .
  • deleted the _site and .sass-cache folders
  • ran a git add . and git status showed that the working directory was clean

Problem

Despite all of that, the updated .gitignore file, and verifying (I think?) that things are clean and good, whenever I run bundle exec jekyll serve and jekyll generates the files, I see .sass-cache and _site show up in my untracked files.

Question

  • What am I doing wrong here? Is my .gitignore formed improperly?
  • How can I ensure that git never shows these directories in the untracked list?

The .gitignore in its current state can be found here.

1条回答
Deceive 欺骗
2楼-- · 2019-03-28 00:40

Your .gitignore file is currently detected as UTF-16LE encoded. Changing encoding to UTF-8 is the solution.

To fix:

  • Open the .gitignore file in a text editor such as Notepad++
  • Change the encoding (in np++, this is via the Encoding menu) to UTF-8 without BOM
  • Save the file.
  • Add the .gitignore file into staging
  • git commit -m "fixed ignore file"

At this point, the ignore file should start working correctly.

查看更多
登录 后发表回答