Ciel
Ciel

Reputation: 4440

.gitignore - difficulty with folder exclusion being ignored

I am trying to ignore a folder from my git pushes using a .gitignore file... and it works for a lot of the things defined in it, but one particular inclusion doesn't seem to be respected.

#Others
assets/

And then in my folder structure...

./
../src
.../web
...../wwwroot
......../assets

but when I go to do a push, it still tries to include the assets folder. I can't figure out why.

Upvotes: 0

Views: 226

Answers (1)

Freyja
Freyja

Reputation: 40834

.gitignore will only ignore untracked files, which means that if the directory was already commited (either intentionally or by accident) when you added it to the .gitignore file, then you have to remove it before Git will ignore it properly.

If this is the case, then you can run git rm -r --cached file-or-directory. (This only "untracks" the file from Git, but doesn't delete it.) If you then run git status, it should show up as "deleted" but not as "untracked". (If it shows up under untracked, then the file isn't ignored by Git). Then you can commit the changes and Git should now ignore the directory.

Upvotes: 1

Related Questions