Visual Studio使用Git忽略不想上传到远程仓库的文件

前言

作为一个.NET开发者而言,有着宇宙最强IDE:Visual Studio加持,让我们的开发效率得到了更好的提升。我们不需要担心环境变量的配置和其他代码管理工具,因为Visual Studio有着众多的拓展工具。废话不多说,直接进入正题。我们日常在使用Visual Studio开发相关的.NET项目时,经常会发现刚拉取下拉的代码什么都没有改动,就是运行了一下就会产生一些需要提交的文件,比如说最常见的bin/Debug, bin/Release,obj/Debug,obj/Release文件。但是我不想把这些文件提交到远程的git代码远程仓库中去,其实这个很简单只需要我们在初次创建项目的时候在项目目录下新增一个忽略文本文件(.gitignore),然后在使用git推送到远程仓库中就好了。

需要忽略提交的文件

图片

配置.gitignore忽略文件,忽略不需要提交的文件

添加Visual Studio的.gitgnore模板到项目中

图片

C#/.NET/.NET Core相关项目的忽略文件模板(VisualStudio.gitignore)

只要是使用VisualStudio开发的项目都可以使用该模板。

  • VisualStudio.gitignore模板GitHub开源地址(该项目中有众多的编程语言或IDE相关.gitgnore配置,可以下载下来直接使用):https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs# Mono auto generated files
mono_crash.*# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/# Visual Studio 2017 auto generated files
Generated\ Files/# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c# Benchmark Results
BenchmarkDotNet.Artifacts/# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/# ASP.NET Scaffolding
ScaffoldingReadMe.txt# StyleCop
StyleCopReport.xml# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc# Chutzpah Test files
_Chutzpah*# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap# Visual Studio Trace Files
*.e2e# TFS 2012 Local Workspace
$tf/# Guidance Automation Toolkit
*.gpState# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user# TeamCity is a build add-in
_TeamCity*# DotCover is a Code Coverage Tool
*.dotCover# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info# Visual Studio code coverage results
*.coverage
*.coveragexml# 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
# Note: 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# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable 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
*.appx
*.appxbundle
*.appxupload# 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
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk# 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
ServiceFabricBackup/
*.rptproj.bak# SQL Server files
*.mdf
*.ldf
*.ndf# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl# Microsoft Fakes
FakesAssemblies/# GhostDoc plugin setting file
*.GhostDoc.xml# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/# Visual Studio 6 build log
*.plg# Visual Studio 6 workspace options file
*.opt# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp# Visual Studio 6 technical files
*.ncb
*.aps# 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/# CodeRush personal settings
.cr/personal# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config# Tabs Studio
*.tss# Telerik's JustMock configuration file
*.jmconfig# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs# OpenCover UI analysis results
OpenCover/# Azure Stream Analytics local run output
ASALocalRun/# MSBuild Binary and Structured Log
*.binlog# NVidia Nsight GPU debugger configuration file
*.nvuser# MFractors (Xamarin productivity tool) working folder
.mfractor/# Local History for Visual Studio
.localhistory/# Visual Studio History (VSHistory) files
.vshistory/# BeatPulse healthcheck temp database
healthchecksdb# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/# Ionide (cross platform F# VS Code tools) working folder
.ionide/# Fody - auto-generated XML schema
FodyWeavers.xsd# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace# Local History for Visual Studio Code
.history/# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp# JetBrains Rider
*.sln.iml

.gitignore忽略规则

基本语法:

  • 以”#”号开头表示注释;

  • 以斜杠“/”开头表示目录;

  • 以星号“*”通配多个字符;

  • 以问号“?”通配单个字符;

  • 以方括号“[]”包含单个字符的匹配列表;

  • 以叹号“!”表示不忽略(跟踪)匹配到的文件或目录;

  • 此外,git 对于 .ignore 配置文件是按行从上到下进行规则匹配的,意味着如果前面的规则匹配的范围更大,则后面的规则将不会生效;

代码示例

# 此为注释 – 将被 Git 忽略*.a       # 忽略所有 .a 结尾的文件
!lib.a    # 但 lib.a 除外
/TODO     # 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
build/    # 忽略 build/ 目录下的所有文件
doc/*.txt # 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt

处理已提交到远程仓库中的文件

可能在开发的时候忘记添加忽略文件配置(gitignore),把这些文件推送到远程仓库中,我们有以下两种做法解决:

  • 1、把本地这些文件删除再提交到远端(前提是这些文件是环境变量文件,假如是无法自动生成的不推荐)。

  • 2、使用以下git 命令:

//当我们需要删除暂存区或分支上的文件, 但本地又需要使用, 只是不希望这个文件被版本控制, 可以使用
git rm -r --cached file_path(文件路径)  //把file_path文件在当前分支的暂存区中删除
git add .                               //提交当前操作本地暂存区
git commit -m 'delete remote somefile'  //提交到本地git仓库
git push                                //提交到远程代码库

如我需要移除某个项目中的obj文件然后提交:

该文件路径为:D:\开发学习-Master\我的训练营\DailyLearning\工作&学习.Net训练营\Application\obj

输入以下命令移除相关不需要跟踪的文件:

git rm -r --cached Application/obj

执行成功后,文件将从该分支中删除(本地还会存在),最后我们提交到远程仓库即可。

图片

图片

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/129102.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux 系统 安装vnc

准备工作 防火墙设置 放行防火墙 firewall-cmd --add-port5901/tcp --permanent #放行5901端口 firewall-cmd --reload #重新加载生效 如果在测试环境,可直接关闭防火墙 systemctl stop firewalld && systemctl disable firewalld关闭selinux s…

Vue2组件化开发(路由与分页组件化)

组件化开发 组件化开发就是将一个页面拆分为多个不同的组件,每个组件依赖的Css,js,资源等放到一起进行开发,组件与组件之间可以进行嵌套,在组件化中,vue只有一个html文件,所有的组件都挂载在该文件上,这种单…

计算机视觉任务图像预处理之去除图像中的背景区域-------使用连通域分析算法(包含完整代码)

原理 通过连通域分析算法能够找到最大的连通域,即图片的主体部分,然后保存该连通域的最小外接矩阵,即可去除掉无关的背景区域 代码 使用连通域分析算法去除图像中的空白部分 并将图像变为统一大小的正方形 from skimage import measure imp…

饥荒联机版 Don‘t Starve Together(WinMac)最新中文学习版

《饥荒联机版》是由Klei自主开发的开放世界冒险游戏。在这个游戏中,玩家将扮演各种各样的人物,这些人物不幸来到了一个神秘的异世界。在旅行中,玩家会邂逅性格各异、能力独特的同伴们,并和他们一起生存下去并征服异世界。游戏中的…

写一个简单实用的Excel工具类

我们在开发中经常要将数据导入成Excel表格供展示&#xff0c;也需要解析Excel中的数据&#xff0c;官方提供的api操作太麻烦&#xff0c;这边封装了一个Excel工具类&#xff0c;可以很轻松的实现Excel的操作 首先加入依赖 <dependencies><!-- EasyPoi 基本库依赖 --…

R语言用jsonlite库写的一个图片爬虫

以下是一个使用R语言和jsonlite库下载图片的程序。首先&#xff0c;我们需要导入jsonlite库和options()函数&#xff0c;然后将代理服务器的主机名和端口号设置为"duoip"和"8000"。接着&#xff0c;我们将URL设置为"https://yun.baidu.com/"&…

【调试技术】用户态查看PEB和TEB

概述&#xff1a;用户态查看进程 PEB 和 TEB(通过windbg附加或启动调试的exe) 0x01 用户态查看 TEB 和 PEB 在双机调试的时候&#xff0c;可以直接使用 !PEB PID 和 !TEB TID 获取进程和线程的相关信息&#xff0c;在用户态这两个命令就会失效。原因就是用户态不支持大写的 !T…

无限上下文,多级内存管理!突破ChatGPT等大语言模型上下文限制

目前&#xff0c;ChatGPT、Llama 2、文心一言等主流大语言模型&#xff0c;因技术架构的问题上下文输入一直受到限制&#xff0c;即便是Claude 最多只支持10万token输入&#xff0c;这对于解读上百页报告、书籍、论文来说非常不方便。 为了解决这一难题&#xff0c;加州伯克利…

Go基础——指针、结构体

1、指针 Go语言指针与C差不多&#xff0c;取地址符是 &&#xff0c;放到一个变量前使用就会返回相应变量的内存地址。 变量是一种使用方便的占位符&#xff0c;用于引用计算机内存地址。一个指针变量可以指向任何一个值的内存地址&#xff0c;它所指向的值的内存地址在 32 …

jenkins实践篇(2)—— 自动打tag的可回滚发布模式

大家好&#xff0c;我是蓝胖子&#xff0c;在上一篇我简单介绍了如何基于特定分支做自动编译和发布&#xff0c;在生产环境中&#xff0c;为了更加安全和快速回滚&#xff0c;我采取的是通过对代码打tag的方式来进行部署&#xff0c;下面我将详细介绍整个发布过程的逻辑。 发布…

IDEA远程调试代码

IDEA->RUN->Edit Configurations 端口随便选一个&#xff0c;选择调试模块&#xff0c;然后用IDEA生成的命令调试 java -agentlib:jdwptransportdt_socket,servery,suspendn,address*:8081 -jar backend-1.18.11.jar &

SteerMouse for mac Mac万能鼠标设置工具 功能介绍

鼠标可谓是用户们在使用电脑时候的必备外接设备呢&#xff01;适合你自己的鼠标设置也绝对能够优化你的Mac使用体验&#xff01;想要更好的Mac体验就试试用Steermouse Mac版吧。它通过软件来自由设置你的鼠标操作&#xff01;在这款万能鼠标设置工具中&#xff0c;用户可以在偏…

MFC String类的初始化学习

之前写过CString的用法&#xff1b; VC CString 编程实例图解_bcbobo21cn, cstring-CSDN博客 下面单独看一下CString的各种初始化方式&#xff1b; void CTest2View::OnDraw(CDC* pDC) {CTest2Doc* pDoc GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for nati…

性能测试知多少---性能分析与调优的原理

最近一直纠结性能分析与调优如何下手&#xff0c;先从硬件开始&#xff0c;还是先从代码或数据库。从操作系统&#xff08;CPU调度&#xff0c;内存管理&#xff0c;进程调度&#xff0c;磁盘I/O&#xff09;、网络、协议&#xff08;HTTP&#xff0c; TCP/IP &#xff09;&…

Codeforces Round 882 (Div. 2)

目录 A. The Man who became a God 题目分析: B. Hamon Odyssey 题目分析: C. Vampiric Powers, anyone? 题目分析: A. The Man who became a God 题目分析: n个人分成k组&#xff0c;每一组的力量都是这样的&#xff0c;那么如果分成k组那么就会有k-1个力量不被统计…

Android 11 Framework 增加自定义API到系统中

基于 Android 11 源码 根据网上的教程, 自己先捣鼓一波: frameworks\base\services 创建 hzyd文件夹 Android.bp内容: android_library_import {name: "services.hzyd",aars: ["MobileSDK-release.aar"],sdk_version: "current", }修改 fra…

tmux工具

B站学习地址&#xff1a;tmux教程

【深度学习】pytorch——Tensor(张量)详解

笔记为自我总结整理的学习笔记&#xff0c;若有错误欢迎指出哟~ pytorch——Tensor 简介创建Tensortorch.Tensor( )和torch.tensor( )的区别torch.Tensor( )torch.tensor( ) tensor可以是一个数&#xff08;标量&#xff09;、一维数组&#xff08;向量&#xff09;、二维数组&…

C#WPF文本格式化模式实例

本文演示C#WPF文本格式化模式实例 WPF 文本渲染优缺点 WPF中的文本渲染和旧式的基于 GDI的应用程序的文本染有很大区别。很大一部分区 别是由于 WPF 的设备无关显示系统造成的,但 WPF 中的文本染也得到了显著增强,能更清晰地显示文本,在 LCD 监视器上尤其如此。 然而,W…

安全与HTTP协议:为何明文传输数据成为争议焦点?

&#x1f3ac; 江城开朗的豌豆&#xff1a;个人主页 &#x1f525; 个人专栏 :《 VUE 》 《 javaScript 》 &#x1f4dd; 个人网站 :《 江城开朗的豌豆&#x1fadb; 》 ⛺️ 生活的理想&#xff0c;就是为了理想的生活 ! 目录 ⭐ 专栏简介 &#x1f4d8; 文章引言 一、H…