7

I have a git project I work on using Visual Studio 2013 and Git.

I have noticed many, if not all, files listed in my .gitignore file are still being listed as pending changes in the Team Explorer window.

However, when doing a git status using bash, I don't see the files (as would be expected). Why is this happening, and more importantly, how can I have Visual Studio treat my .gitignore file the same as git bash?

.gitignore file:

GitIgnore file

Pending Changes Window (Team Explorer):

Pending Changes Window

Adam Drewery
  • 1,508
  • 1
  • 17
  • 25
  • Where is your repository's working directory in the above example? – Edward Thomson Mar 21 '14 at 14:58
  • The folder sturcture would be `C:\MyRepository\Source\MyProject\intranet\dotnet` where `MyRepository` is the working directory and the `dotnet` folder corresponds to that shown in the second screenshot. The `.gitignore` file is in the working directory. – Adam Drewery Mar 23 '14 at 13:00

4 Answers4

4

I was having the same problem with linked files. Team Explorer claimed I was adding the linked files, so I added them all to my .gitignore. git status was now clean, but Team Explorer continued to show these files as being added.

Right clicking the list of files in Team Explorer changes and selecting Undo seemed to work. The files themselves were not deleted, and they were removed from my list of changes.

Seems like Team Explorer just doesn't immediately pick up on changes to .gitignore. Hope this helps.

Jim Skerritt
  • 4,348
  • 2
  • 28
  • 25
  • 4
    If your files are already marked as "included changes" then no, adding them to `.gitignore` will not retroactively have an affect. – Edward Thomson Mar 21 '14 at 14:59
  • 1
    I have to do this all the time- it is not a permanent solution though- the files keep popping up, and due to the application I am working on these files can be in their hundreds! Very tedious to click `undo` for every single one. – Adam Drewery Mar 23 '14 at 12:58
  • 1
    +1 Such a crappy solution, but better than nothing :( – Carrie Kendall Aug 11 '14 at 15:03
4

To make Visual Studio 2013 include changes you made to the .gitignore file, delete the file ms-persist.xml in your solution's .git folder.

Amged Rustom
  • 1,739
  • 3
  • 19
  • 25
1

I want to share my very similar experience in Visual Studio 2017, even though in my case git on the command line was not acknowledging the files listed in my .gitignore.

I had used Powershell to create my .gitignore file with the command echo '' > .gitignore. This created a file encoded in UCS-2 LE BOM instead of UTF-8. As a result, git would list the file in git status but none of the specified files were ignored until I converted it to UTF-8. So... be careful about creating an empty file with such a Powershell command, as much as I would love to get on the UTF-16 bandwagon.

As referenced in another answer, I should have used a command like echo '' | Out-File .\.gitignore -encoding Utf8 to initially create the file, although that creates a UTF-8 file with the BOM.

Also, the following command, as I learned from yet another answer, will copy the content from a file and create the new file with just regular UTF-8 without the BOM:

Get-Content -Encoding utf8 .\.gitignore.bak | Out-File -Encoding utf8 .\.gitignore
Spencer Williams
  • 821
  • 10
  • 20
0

This is an old question but still relevant. In my case on Visual Studio Community 2015, .gitignore is being processed BUT it interprets the rules incorrectly.

For example, this .gitignore file works in the CLI git client - it ignores everything but the subtree in /Assets/Scripts, and the .gitignore file.

# Ignore everything
*
# But descend into directories
!*/
# Recursively allow files under subtree
!/Assets/Scripts/**
#don't ignore this file
!.gitignore

When VS parses the above .gitignore file, it seems to incorrectly interpret an allowed folder as: Allow this folder, plus all files and folders within it recursively - so every subtree incorrectly shows up in the repository. To achieve the same result as the code above from within Visual Studio, I had to change it to this: Note the following code works in VS, but no longer works in the Git CLI.

# Ignore everything
*
#But don't ignore the /assets folder
!/Assets/
#Ignore everything inside the assets folder
/Assets/*
#but don't ignore the Assets/Scripts subtree
!/Assets/Scripts
#don't ignore this file
!.gitignore
Chris H
  • 932
  • 4
  • 8