如何正確實作使用 git ignore 不將 .json 檔案提交到我的存盤庫?
我嘗試觀看 youtube 視頻尋求幫助,但在遵循他的提示后,我的 json 檔案仍在上傳。
uj5u.com熱心網友回復:
如果你想忽略,你必須將.gitignore你的存盤庫的頂級目錄.git。
這是github的鏈接,它維護了.gitignoreC#。當然,您可以隨意編輯它,但最常見的事情已經為您完成了。
更新的一般方式.gitignore很簡單。添加*.anyextension以忽略具有該擴展名的任何檔案。如果您想忽略該檔案中更復雜的內容,這可能會變得更加復雜,但就像我說的那樣,它們中的大多數已經為您完成了。
例如
MyGitRepoFoder -> (contents) .git(hidden) you want to place the .gitignore here
使用它是我用于每個 C# 專案的東西,我還添加了忽略任何帶有JSON擴展名的東西
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# Visual Studio (>=2015) project-specific, machine local files
.vs/
# User-specific files
*.suo
*.user
*.sln.docstates
*.userprefs
# ignore Xamarin.Android Resource.Designer.cs files
**/*.Droid/**/[Rr]esource.[Dd]esigner.cs
**/*.Android/**/[Rr]esource.[Dd]esigner.cs
**/Android/**/[Rr]esource.[Dd]esigner.cs
**/Droid/**/[Rr]esource.[Dd]esigner.cs
# Xamarin Components
Components/
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
x64/
build/
bld/
[Bb]in/
[Oo]bj/
# 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
*_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
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# 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 addin-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
_NCrunch_*
.*crunch*.local.xml
# 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
# NuGet Packages Directory
packages/
*.nuget.targets
*.lock.json
*.nuget.props
## TODO: If the tool you use requires repositories.config uncomment the next line
#!packages/repositories.config
# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
# This line needs to be after the ignore of the build folder (and the packages folder if the line above has been uncommented)
!packages/build/
# Windows Azure Build Output
csx/
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
.DS_Store
*.bak
# 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/
.vscode/settings.json
#Ignore APK
*.apk
#Ignore JSON
*.json
uj5u.com熱心網友回復:
要忽略特定型別的所有檔案,請使用通配符 ( *) 后跟檔案擴展名。
以下將忽略專案中的所有 JSON 檔案
*.json
旁注:您.gitignore需要位于頂級目錄中。換句話說,與解決方案檔案所在的目錄相同。
uj5u.com熱心網友回復:
我認為.gitignore在你的情況下更新是不夠的。您需要停止跟蹤 json 檔案。關鍵是,一旦檔案被 git 跟蹤,然后你忽略它 - 無論如何 git 不會洗掉它。因為它停止跟蹤該檔案的更改,而不是檔案本身。
所以,首先添加*.json到.gitignore.
然后停止跟蹤之前已經添加到 git 的任何 json 檔案(檔案是以下命令的檔案名):
git rm --cached <file>
uj5u.com熱心網友回復:
https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 這里是一個通用的.gitignore 檔案。在包含解決方案的主目錄中使用它,它應該可以作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/531303.html
標籤:混帐
