TFS/Git extensions seems to ignore .gitignore

2019-01-17 15:22发布

问题:

I'm running VS 2013 Update 3 with the 'Visual Studio Tools for Git' extension. This extension is for users of both team explorer and Git and I have no other Git and TFS related extensions installed and running. I use Microsoft's TFS Cloud service to backup and share my work.

Everything worked as expected for a few months. I want to be able to use this VS extension again, but the problem is that the files that should be ignored by .gitignore are being included by default. The same Git repository when viewed from the command line does not have this problem and works as expected.

Possibly important: I have at one time half-way set up a straight TFS account online but never used it locally and that never correlated with any problems I have mentioned here. Also, a long time ago I had to follow the advice in another posting to remove these binary files from version control because I added the .gitignore file too late. Since the command line doesn't have this problem I think something else is at work and that --hard reset actually worked as intended.

What is the problem with VS? Is there some way to change a setting or generally correct the oversight to ignore the files in the .gitignore file in the Git directory but not ignore the .gitignore file?

To head off some potential questions: I confirmed that the directories, and branches are the same on both interfaces by observing that all changes are added to Git/TFS and Posh Git as well as Git Bash and all other Git interfaces I have tried. The only problem is that additional files that should be ignored are not ignored in the VS extension.

Here is a sample of the .gitignore file that I use, which was produced by VS:

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

回答1:

We recently had the the same problem with the VS2013 git provider ignoring the .gitignore for only a few files. It turned out, there was ms-persist.xml in the .git folder with the two relevant sections <TrackedFiles> and <IgnoredFiles>.

As suggest in a blog post by Eric Nelson closing VS, deleting the file and restarting VS again solved the problem.



回答2:

You say that you are using VS 2013? If so, you do not need the extra git tools. I don't have them installed on my VS 2013, can use TFS with GIT just fine, and I don't experience the issue with .gitignore being ignored.

You can even manage the .gitignore via the IDE GUI so formatting should always be in the format desired by TFS/VS: http://msdn.microsoft.com/en-us/library/vstudio/hh967655.aspx#ignore

As stated in the Requirements from: https://visualstudiogallery.msdn.microsoft.com/abafc7d6-dcaa-40f4-8a5e-d6724bdb980c:

Note: Visual Studio 2013 includes Git tools by default so these tools are not needed. Learn more on MSDN: http://msdn.microsoft.com/en-us/library/vstudio/hh850437.aspx