2

I have a .gitignore file with the following contents:

.vs/

I run the following commands

git add .gitignore
git commit -m 'adding ignore file'

In my .vs folder, I have a text file named test.txt.

When I type git status, I see the following output

On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .vs/

nothing added to commit but untracked files present (use "git add" to track)

What am I missing here?

yxrkt
  • 424
  • 4
  • 12
  • 1
    Run `git status -uall` to see which files *within* `.vs/` are being not-ignored; but in general, git will look inside `.vs/` despite the ignore directive if there are already some tracked files *within* `.vs/` so that Git *must* look inside `.vs/` to look at the *tracked* files. Use `git ls-files --stage` to see *all* your tracked files (note that this produces a lot of output in a big repository!). – torek Sep 21 '18 at 04:45

4 Answers4

2

Found my solution here (Visual Studio was adding Chinese characters to my .gitignore also)

My .gitignore was saved with unicode encoding.

This is because I created my .gitignore file via PowerShell like so

".vs/" > .gitignore

I did this because explorer doesn't let you create a text file with a leading period. My solution:

".vs/" | Out-File -Encoding ascii -FilePath .gitignore
yxrkt
  • 424
  • 4
  • 12
1
  1. Use correct patterns. .vs must be in same directory as .gitignore, if not, correct the path.
  2. Do commit .gitignore, so that others benefit from it.
  3. If something is already included (tracked) by git, and you later add it to .gitignore, it won't cause git to forget it. For this:
    1. Use git rm --cached <filePath> for file(s)
    2. Use git rm -r --cached <dirPath> for a directory
S.D.
  • 29,290
  • 3
  • 79
  • 130
0

First, you don't need to add .gitignore to the index and commit it for said file to be effective.

A git status done after creating/updating a .gitignore will work.

Second, make sure your .gitignore is at the same level (or above) as .vs/ (not inside it)

Third, check its eol (end of line, make sure it is linux-style)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

What I think from the logs is that you have added the folder in .gitignore but still since it was committed earlier you want to remove it.

If is present in earlier commits and you want to remove it. You can use :-

git rm --cached .vs/

this will mark the folder as deleted from index but it will be unchanged in local.

Then use:

git commit -m "<Msg showing removing file from git tracking.>"

I have taken a certain assumption, Please clarify if it's not what you need.

Rishabh Agarwal
  • 1,988
  • 1
  • 16
  • 33