windows Gitignore 不会忽略 Windows7/8 上 Visual Studio 2015 RC 的 .vs 文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30868544/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:08:17  来源:igfitidea点击:

Gitignore won't ignore .vs folder for Visual Studio 2015 RC on Windows7/8

windowsgitdirectorygitignorevisual-studio-2015

提问by user5015546

This one has stumped several team members on Windows, running Git. We've tried all sorts of explicit and wildcard entries in .gitignore however items in the hidden .vs/ folder as a part of Visual Studio 2015 RC keep getting committed. Since those are individual settings for developers, they are obviously always different and show up in a git diff. Are there any hacks out there to ignore everything in the top-level .vs/ folder in the repo?

这个问题在运行 Git 的 Windows 上难倒了几个团队成员。我们已经在 .gitignore 中尝试了各种显式和通配符条目,但是作为 Visual Studio 2015 RC 一部分的隐藏 .vs/ 文件夹中的项目不断被提交。由于这些是开发人员的个人设置,它们显然总是不同的,并显示在 git diff 中。是否有任何黑客可以忽略回购中顶级 .vs/ 文件夹中的所有内容?

回答by Bravo Yeung

Follow the steps below, the issue will be solved.

请按照以下步骤操作,问题将得到解决。

Step 1: Add following content to the file .gitignore.

步骤 1:将以下内容添加到文件 .gitignore 中。

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

# 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/
# 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

# DNX
project.lock.json
artifacts/

*_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

# 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

# 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

# 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 ignoreable 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
*.pfx
*.publishsettings
node_modules/
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

# 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

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# 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

Step 2: Make sure above operation take effect

第二步:确保以上操作生效

If the issue still exists, that's because settings in .gitignorecan only ignore files that were originally not tracked. If some files have already been included in the version control system, then modifying .gitignoreis invalid. To solve this issue completely, you need to open Git Bashrunning following commands in the repository root folder.

如果问题仍然存在,那是因为.gitignore中的设置只能忽略最初未跟踪的文件。如果版本控制系统中已经包含了一些文件,那么修改.gitignore是无效的。要彻底解决此问题,您需要打开Git Bash,在存储库根文件夹中运行以下命令。

$ git rm -r --cached .
$ git add .
$ git commit -m 'Update .gitignore'

Certainly, you can also use Package Manager Consoleof Visual Studio to do the things in Step 2. Use PM consoleThen the issue will be completely solved.

当然,您也可以使用Visual Studio 的Package Manager Console来完成步骤 2 中的操作使用 PM 控制台那么问题就彻底解决了。

回答by David Deutsch

If they are showing up in a git diff, then the files are already being tracked, whereas .gitignore only affects files that are untracked. You will need to remove the files from source control with git rm --cached, and then.gitignore will affect them.

如果它们出现在 a 中git diff,则文件已经被跟踪,而 .gitignore 只影响未跟踪的文件。您需要使用 将文件从源代码管理中删除git rm --cached然后.gitignore 将影响它们。

Note that when you do this, other developers will have their files deleted locally when they do their next git pull. So before doing so, they may want to make a backup of those files.

请注意,当您执行此操作时,其他开发人员将在执行下一次git pull. 因此,在这样做之前,他们可能希望备份这些文件。

回答by Chaim Eliyah

In our case, the .vsdirectory had been added to source control when I initialized the repository. Thus, the line in .gitignore:

在我们的例子中,.vs当我初始化存储库时,该目录已添加到源代码管理中。因此,行中的.gitignore

/.vs

didn't do anything until I deleted the directory and checked in the changes (similar to what TPoschel is saying above, but with the difference that checking in the deleted directory is what fixed it, as I had already checked in the .gitignorefile).

直到我删除目录并签入更改后才执行任何操作(类似于上面 TPoschel 所说的,但不同的是,检查已删除的目录是修复它的内容,因为我已经签入了.gitignore文件)。

回答by TPoschel

I ran into this issue prior to committing anything to my repository. I erroneously thought that just having the .gitignore file in the directory would prevent VS from recognizing the files as 'Changes'. You have to first commit the .gitignore file before git will start ignoring the files specified within it.

在向我的存储库提交任何内容之前,我遇到了这个问题。我错误地认为目录中只有 .gitignore 文件会阻止 VS 将文件识别为“更改”。您必须先提交 .gitignore 文件,然后 git 才会开始忽略其中指定的文件。

回答by Ben

It works this way for me: open your git ignore file and add the following to the list:

它对我来说是这样工作的:打开你的 git ignore 文件并将以下内容添加到列表中:

.vs/

.vs/

回答by Fabiavill

I ran into this issue and I found an easy way of fixing the "git tracking the files already" thing.

我遇到了这个问题,我找到了一种简单的方法来解决“git已经跟踪文件”的问题。

  1. Backup all the relevant files in your git folder on your PC to a seperate location (normally something like c:/user/source/repos if you didn't specify someplacec else).

  2. Delete all the relevant files in the git folder.

  3. Open Visual Studio and push this delete to the server.

  4. Paste all the files back in.

  5. Push this to the server.

  1. 将 PC 上 git 文件夹中的所有相关文件备份到单独的位置(如果您没有指定 someplacec else,通常类似于 c:/user/source/repos)。

  2. 删除 git 文件夹中的所有相关文件。

  3. 打开 Visual Studio 并将此删除推送到服务器。

  4. 重新粘贴所有文件。

  5. 将其推送到服务器。

This should be an easy way of getting rid of all those temporary files and anything else you specified on your .gitignore for your online git folder that it's already tracking.

这应该是摆脱所有这些临时文件以及您在 .gitignore 上为您的在线 git 文件夹指定的任何其他内容的简单方法,这些文件已经在跟踪。

回答by ingconti

I usually add .vs at start, when repo is clean. but I can confirm git obeys to:

我通常在开始时添加 .vs,当 repo 是干净的。但我可以确认 git 遵守:

.vs

.vs

in .gitignore.

在 .gitignore 中。

And as other says, remove locally and then commit/push.

正如其他人所说,在本地删除然后提交/推送。