Wolfpack'08
Wolfpack'08

Reputation: 4128

.gitignore being ignored despite `rm --cached`?

works-as-designed

Similar: 35735862/gitignore-difficulty-with-folder-exclusion-being-ignored

Goal:

I'd like git add . to not result in my file being tracked.

Build info: ##`

git version 2.24.1.windows.2` using Windows PowerShell on Windows 10.

First attempt: mysf.txt

My file is mysf.txt (my_secret_file).

./gitignore contains: mysf.txt, but I've also tried absolute paths and .\mysf.txt to no effect.

git add . > git status reports that mysf.txt being tracked.

git rm --cached mysf.txt > git commit > git status reports that the file is "untracked".

Second Attempt: secret_file.txt

So, I deleted mysf.txt and made a new file called secret_file.txt.

Now, I've ensured that the text, secret_file.txt, is added to .gitignore before doing the following:

git add .
git echo "this file is to be ignored." > secret_file.txt
git commit
git status

secret_file.txt is not tracked. Now, I type git add . and secret_file.txt is tracked!

Upvotes: 1

Views: 67

Answers (1)

Wolfpack'08
Wolfpack'08

Reputation: 4128

Solution:

Change the encoding of .gitignore to utf-8.

This can be accomplished in a number of ways. Notepad++ has a drop-down menu called 'encoding'; notepad has encoding options in its save-as dialog; linux subsystem's touch command can be used rather than batch's echo command to create files via commandline.

Converting a file to utf-8: Get-Content .\test.txt | Set-Content -Encoding utf8 test-utf8.txt thanks to post by DavidPostill.

PowerShell Command:

Set-Content <filename> -Encoding <Encoding>

For example: Set-Content my_file.txt -Encoding utf8(*1).

*1. Please note: case-sensitive!

Upvotes: 1

Related Questions