Saturday, 8 July 2017

Ignoring Visual Studio 2017 Created Files in Git

Visual Studio 2017 creates few files such as slnx.sqlite, .suo and these files often give trouble if you get it added to a branch in Git version control. Every time you open a solution in Visual Studio 2017, these files are indicated as pending changes and you are unable to do a pull, push etc. without undoing or committing these files. This is annoying since you actually do not want these to be added as changes to version control repository. You can try completely removing the files not needed from repository but if you are not willing to go through somewhat risky procedure, what options you have for solving this problem?


Let’s look at how to fix this issue.

.gitignore

Adding unwanted files to .gitignore works as long as you have not initially committed them to any branch. But in this case where it is already committed adding .gitignore entry such as /.vs/slnx.sqlite does not help.image

Ignore changes to the files

You can run below command to ignore the changes to these files by assuming they are unchanged.

git update-index --assume-unchanged filename

To run the command open command prompt from team explorer window of Visual Studio by right clicking on the repository name of the connect page.image

The command git update-index --assume-unchanged slnx.sqlite gives error “fatal: Unable to mark file slnx.sqlite” because it actually cannot find the file. 1

To find the correct paths you can execute git ls-files command and use the path listed to mark the file. You can list git untracked files as well by executing git ls-files -o but untracked files cannot be marked. Adding them to gitignore would be sufficient.image

Providing correct path to file from the location you are running the command will make it execute without error message.SNAGHTML45c4ff67

slnx.sqlite file no longer considered as changed.image

You can undo the the assume-uchanged state by executing command below.

git update-index –-no-assume-unchanged filename

No comments: