由于这些是开发人员的个别设置,它们显然总是不同,并显示在git diff中。
我该如何解决它以忽略存储库中顶级.vs文件夹中的所有内容?
按照以下步骤操作,问题将会得到解决。
步骤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
步骤二:确保上述操作生效
如果问题仍然存在,那是因为.gitignore文件中的设置只能忽略最初未被跟踪的文件。如果某些文件已经包含在版本控制系统中,则修改.gitignore是无效的。 要完全解决此问题,您需要在存储库根文件夹中打开Git Bash并运行以下命令。
$ git rm -r --cached .
$ git add .
$ git commit -m 'Update .gitignore'
.
作为 git rm
的参数,因为那样会删除所有东西!我猜你只想删除现在要排除的部分,比如 .vs
文件夹。 - ChrisWgit diff
中,那么这些文件已经被跟踪了,而 .gitignore 只影响未跟踪的文件。你需要使用 git rm --cached
将这些文件从源代码控制中移除,然后 .gitignore 才会生效。git pull
时,它们的本地文件将被删除。所以在这样做之前,他们可能需要备份这些文件。在我们的情况下,当我初始化仓库时,.vs
目录已经被添加到源代码控制中。因此,在.gitignore
文件中的这一行:
.vs/
/.vs
直到我删除了目录并提交更改后 (类似于TPoschel上面所说的,但不同之处在于检查已删除的目录才是解决问题的关键,因为我已经检查过.gitignore
文件了) 才做了任何事情。
.vs/
.vs
的文件夹(您不需要尾随斜杠),即使在子目录中出现一个也是如此。@ChaimEliyah的答案仅忽略根目录中的.vs
文件夹。 - bobobobo这个答案与上面的答案类似,但是当一个有效的.gitignore文件被放置时,如果项目已经被检入分支并且它们出现在源存储库中,则详细说明了实际步骤。
.vs
目录,请验证当前分支中没有从该目录中暂存的内容。如果有,请取消暂存。.vs
的目录级别。git rm --cached -r .vs
。备份PC上git文件夹中的所有相关文件到另一个位置(通常是c:/user/source/repos,如果你没有指定其他地方)。
删除git文件夹中的所有相关文件。
打开Visual Studio并将此删除推送到服务器。
粘贴回所有文件。
将其推送到服务器。
在向仓库提交任何内容之前,我遇到了这个问题。我错误地认为只要在目录中有.gitignore文件,VS就不会将文件识别为“更改”。您必须先提交.gitignore文件,然后git才会开始忽略其中指定的文件。
如果在项目创建过程中错过了.gitignore文件。
解决方法:
创建一个新的类似项目
复制.gitignore文件和.gitattributes文件,然后粘贴到旧解决方案中。
清除git缓存。
git rm -r --cached .
git add .
git commit -m 'Remove ignored files'
.gitignore
文件吗? - nwinklergit add .
..? - bobobobo