Wednesday, August 3, 2016

Why won't git ignore .vs/config/applicationhost.config?

In this case, I was trying to ignore anything in the .vs/ folder (mainly to ignore .vs/config/applicationHost.config which is iisexpress' config file). This directory, created by Visual Studio 2015, contains machine specific data (similar to why you don't want to store .suo files in the repository).

The pattern I went with (.vs/) was both what I came up with originally and the same pattern used by the gitignore template for visual studio.

The pattern was stored in .gitconfig in the repository root directory.

But every time I ran git check-ignore --verbose .vs/config/applicationHost.config the file would not match the pattern.

Oddly enough, a different file in .vs/ matched the .gitignore pattern!

It turns out that .gitignore will not match files that have ever been tracked by git. This file was mistakenly checked in at some point in the past. To check .gitignore patterns without regard for checkin history, use the --no-index flag (eg., check-ignore --verbose .vs/config/applicationHost.config).

To stop tracking the file use git rm --cached path/to/file.ext

No comments :

Post a Comment