Visual Studio Team Explorer - GIT: Automatically ignoring new files
Asked Answered
M

3

10

Whenever I create a new file such as a class file (.cs), the file is automatically ignored by GIT (although still included in the project). Is it something with my .gitignore file or some Visual Studio setting? A bug?

Interestingly, I have 7 projects under my solution and only 1 project has this behavior.

Why do I think it's ignored and not untracked? Here's the answer:

1- Normally Visual Studio will track all new .cs files, that's what it does in all my projects except for this one.

2- The new file's Version Control Status Icon is a red circle (with a rectangle in the middle), which if hovered over will show the word "Ignored". In addition, if I right click on the file I can see the option "Add Ignored File to Source Control."

Here's the .gitignore file (on the same folder as that of the .git folder):

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

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

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Visual Studio 2015 cache/options directory
.vs/
.vscode/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# Visual Studio code coverage results
*.coverage
*.coveragexml

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs

# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf
*.ndf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/

# Typescript v1 declaration files
typings/

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions

# Paket dependency manager
.paket/paket.exe
paket-files/

# FAKE - F# Make
.fake/

# JetBrains Rider
.idea/
*.sln.iml

# CodeRush
.cr/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc

# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config

# Telerik's JustMock configuration file
*.jmconfig

# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
Mencius answered 11/9, 2018 at 12:44 Comment(7)
I think it is Git's standard behavior to treat new files as being untracked, until you manually add them.Hemorrhoidectomy
We can only guess if you don't include the .gitignore or more information here.Borage
@Borage it took me a while, but the git file is there. Sorry for the delayMencius
Can you explain more what you mean by "automatically ignored"? Where do you see it being ignored (as opposed to untracked as @TimBiegeleisen indicated)? What is the output of git status?Transoceanic
@bto, the new file's Version Control Status Icon is a red circle (with a rectangle in the middle), which if hovered over will show the word "Ignored". In addition, if I right click on the file I see the option "Add Ignored File to Source Control"Mencius
@TimBiegeleisen, Visual Studio is supposed to add the file to source control automatically, that is how it behaves in all projects(even within the same solution) except for this one.Mencius
I have this silly problem off and on. I don't know what triggers it. Functions correctly for me at work, doesn't work at home for some reason or another. I have to keep manually adding the files that are automatically ignored. I checked my ignore file, nothing in there to indicate why this is happening. I've restarted VS and that helps sometimes. Can't help but notice this happened after a recent upgrade. I use git bash most of the time for this exact reason.Heptavalent
M
10

Eureka!!. My project name was matching the pattern *.sap on the .gitignore file, so all new files on that project would automatically be ignored. I removed the *.sap pattern from the .gitignore file and now everything works as expected.

Mencius answered 26/9, 2018 at 19:15 Comment(1)
I am working on a project with SAP concur. I was scratching my head, then I saw this answer. This was my issue. Project name ended in .SAPTibbitts
M
2

It happens form time to time. Just close and reopen Visual Studio.

Because of this inconsistency (I think it's a bug) I also look for untracked files in another "visual" git app (SourceTree) to make sure that nothing is left behind inside some directory.

Mission answered 26/9, 2018 at 11:6 Comment(1)
In my case it never goes away, even restarting VSMencius
B
0

I tested your .gitignore file locally, and it works fine. My best guess is that you need to stage your files. I think you are confusing ignored files with untracked files.

Git is seperated into three "directories". When you "track" a file it means that changes between these three directories are kept. Ignored files are not tracked.

Working Directory The working directory is basically what is on your hard drive. Git will track differences on files and folders between the working directory and the staging area. Everything that is untracked is in the working directory. And every change to a tracked file is contained in the working directory.

Staging area Whenever you "stage" something (by using git add) you stage the changes. This means that you copy the changes from the working directory to the staging area. When you stage a file or folder, the files are kept in the working directory (i.e. the harddrive), but copied to the staging area as well.

The staging area a sort of middle ground between a commit and an untracked file. You need to stage your files before you can commit them.

Local Branch When you commit something you take whatever is currently staged, and make a commit, and append that commit to the current branch. This will also remove the changeset from the stagin area.

Blancheblanchette answered 11/9, 2018 at 22:8 Comment(4)
Thanks for the explanation @Andersnk, however, the flow is different when using Visual Studio. Normally in VS a new file will be automatically tracked and included in source control (I assume VS will stage it automatically), leaving me with just the last step of committing it.Mencius
Visual studio will not track files automatically, nor stage them unless you install a plugin that does that for you.Blancheblanchette
I am using Visual Studio's Team Explorer and haven't installed any plugin. I've used VS and GIT like this for more than a year and new files always show in the "Changes" section ready to be commited. This is what I mean by them being tracked automatically. Whatever commands VS executes behind scenes I do not know.Mencius
Well, your plugin might be broken. It's not your .gitignore file thats broken.Blancheblanchette

© 2022 - 2024 — McMap. All rights reserved.