Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git still shows files as untracked despite .gitignore and rm -r --cached. What did I do wrong?

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.

like image 744
SeanKilleen Avatar asked Oct 07 '14 14:10

SeanKilleen


People also ask

How do I fix nothing added to commit but untracked files?

The solution: To fix this error, you may either add the untracked files to your Git repository (as advised by the warning message) or add them to your . gitignore file. After that, either option should allow the git pull to succeed.

Why are my files untracked git?

Untracked files are the ones still not versioned—”tracked”—by Git. This is the state of new files you add to your repository. That basically means Git is aware the file exists, but still hasn't saved it in its internal database.

Does git clean remove untracked files?

By default, git clean will only remove untracked files that are not ignored. Any file that matches a pattern in your . gitignore or other ignore files will not be removed. If you want to remove those files too, you can add a -x to the clean command.


1 Answers

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.

like image 132
David Jacquel Avatar answered Oct 16 '22 23:10

David Jacquel