简体   繁体   English

为什么 Visual Studio 将我添加的 .cs 文件标记为“已忽略”?

[英]Why does Visual Studio mark my added .cs files as "ignored"?

I cloned an existing but almost empty project on my local machine through GitHub for Windows.我通过 GitHub for Windows 在本地机器上克隆了一个现有但几乎是空的项目。 Then I opened it in VS 2017 and added a few classes after what they all became marked up as "ignored" with red icons with "minus" sign on them.然后我在 VS 2017 中打开它并添加了一些类,之后它们都被标记为“忽略”,带有红色图标和“减号”符号。

When I tried to make a commit, (I want to make commits and push through GitHub App), non of the files where pushed.当我尝试提交时(我想提交并通过 GitHub 应用程序推送),推送的文件没有。

Then I tried right-clicking on the files and adding them to source control.然后我尝试右键单击文件并将它们添加到源代码管理中。 Then "minus" signs became "+".然后“减号”变成了“+”。

I also thought maybe the problem lies in the fact that I didn't stage them.我还认为问题可能在于我没有上演它们。 So I did (in VS).所以我做了(在VS中)。 But I still cannot push these files.但我仍然无法推送这些文件。 After an attempt to make a commit in GitHub app all my .cs files again become marked up with "minus" sign.尝试在 GitHub 应用程序中提交后,我的所有 .cs 文件再次被标记为“减号”。

What is the reason of it and how to make them not be signed as "ignored"?这是什么原因以及如何使它们不被签名为“忽略”?

They are (most likely) being ignored by .gitignore file.它们(很可能)被 .gitignore 文件忽略。

If you can't see anything obvious (check substrings of the file name as well as extension), then look for these and remove them:如果您看不到任何明显的内容(检查文件名的子字符串以及扩展名),请查找并删除它们:

/* !/content/

Not sure if this helps the @Tanya, and here's my partially similar experience.不确定这是否有助于@Tanya,这是我部分相似的经历。

And sadly (as a reflection on my powers of observation) it turned out to be exactly as @goamn had suggested.可悲的是(作为对我观察力的反映)结果与@goamn 所建议的完全一样。

I was building a new console app (very short list of files) to help me do a backup activity, and I had called the VS project “backup”.我正在构建一个新的控制台应用程序(非常短的文件列表)来帮助我进行备份活动,我将 VS 项目称为“备份”。

What I missed (at first and second glance) was that in the .gitignore was the line (in the “Backup & report files” of all likely places!):我错过的(第一眼和第二眼)是 .gitignore 中的行(在所有可能位置的“备份和报告文件”中!):

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

Merely removing this line from that file, even after I had (what appeared to me to be a horked) repository already set up and non functional in github, fixed it right up.仅仅从该文件中删除这一行,即使在我已经设置了(在我看来是一个笨蛋)存储库并且在 github 中不起作用之后,也可以直接修复它。 I was able to commit the files with no problem.我能够毫无问题地提交文件。

Hope that helps.希望有帮助。

Say the .gitignore file has this:假设.gitignore文件有这个:

*.log

in it.在里面。

Now, a project that's named with a .Log suffix will not be committed(for example a project called CompanyName.Domain.Service.SubService.Log )现在,以.Log后缀命名的项目将不会被提交(例如名为CompanyName.Domain.Service.SubService.Log的项目)

To add such a project to source control, you'd need to manually add it using:要将这样的项目添加到源代码管理中,您需要使用以下方法手动添加它:

git add <RootFolder>/<CompanyName.Domain.Service.SubService>.Log/* -f

This will force commit the change contrary to the opinion of the .gitignore file.这将强制提交与.gitignore文件意见相反的更改。 However, this does not remove the .log from the .gitignore file.但是,这不会.gitignore文件中删除.log But once the force commit happens, the project is already in source control and will therefore not be subject to the .gitignore file.但是一旦发生强制提交,该项目已经在源代码控制中,因此将不受.gitignore文件的约束。 Thereafter, commits to this project will be committed.此后,将提交对该项目的提交。

您需要先添加,确保它们已上演,提交,然后推送

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的.cs和.designer.cs文件没有出现在Visual Studio中的我的最佳文件下? - Why my .cs and .designer.cs files doesn't appears under my uitest files in Visual Studio? 为什么在Visual Studio中所有类文件都以.vb扩展名创建而不是.cs文件? 我需要.cs文件 - Why all class files are creating with .vb extension and not as .cs file in my Visual Studio? I need .cs file 在Visual Studio 2010中,为什么“计算代码指标”会忽略.xaml.cs文件? - In Visual Studio 2010, why does “Calculate Code Metrics” ignore .xaml.cs files? 随机cs文件无法在visual studio 2012中打开 - random cs files not opening in visual studio 2012 Visual Studio Code 运行单个.cs 文件 - Visual Studio Code run individual .cs files .NET c#:为什么Visual Studio希望我将文件放入c:\\…\\ myConsoleApplication \\ bin \\ Debug - .NET c#: Why does Visual studio expect me to put my files in c:\…\myConsoleApplication\bin\Debug 将 KeyValuePair 枚举传递给 FormUrlEncodedContent 构造函数时,为什么 Visual Studio 会生成警告 CS620? - Why does Visual Studio generate warning CS620 when passing KeyValuePair enumeration to FormUrlEncodedContent constructor? 为什么Visual Studio会在temp文件夹中生成如下文件.NETFramework,Version=v4.5.AssemblyAttributes.cs - Why does Visual Studio generates the following file .NETFramework,Version=v4.5.AssemblyAttributes.cs in the temp folder 为什么Visual Studio不显示#warning指令(CS1030)生成的警告? - Why does not Visual Studio display warnings generated by the #warning directive (CS1030)? 为什么Visual Studio两次显示重要的任务列表项,一次带有感叹号,一次没有感叹号? - Why does Visual Studio show important task list items twice, once with the exclamation mark and once without?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM