简体   繁体   中英

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. 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.

When I tried to make a commit, (I want to make commits and push through GitHub App), non of the files where pushed.

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). 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.

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.

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.

And sadly (as a reflection on my powers of observation) it turned out to be exactly as @goamn had suggested.

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”.

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!):

# 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. I was able to commit the files with no problem.

Hope that helps.

Say the .gitignore file has this:

*.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 )

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. However, this does not remove the .log from the .gitignore file. But once the force commit happens, the project is already in source control and will therefore not be subject to the .gitignore file. Thereafter, commits to this project will be committed.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM