首页 > 其他分享 >gitignore文件的使用

gitignore文件的使用

时间:2024-08-09 15:27:08浏览次数:9  
标签:文件 忽略 build 使用 output 目录 ### gitignore

在使用GitLab进行版本控制时,如果你想要忽略一些文件或目录不被提交(比如生成的权重、预测的图片等),你可以在项目的根目录下创建或编辑一个.gitignore文件。在这个文件中,你可以列出那些你希望Git忽略的文件和目录的模式。

1. 基本语法

  • 每条规则占一行
  • 空白行或以 # 开头的行:这些行将被忽略。
  • 标准 glob 模式(通配符):可以包含 *(匹配任意数量字符)、?(匹配单个字符)、[abc](匹配方括号内的任意一个字符)。
  • 目录:如果要忽略目录,需要在模式后面加上 /
  • 否定规则:在模式前加上 ! 来包含那些被之前规则排除的文件

2. 使用说明

(1) 忽略所有.jpg文件:

*.jpg

(2) 忽略 build文件夹

build/      		#忽略目录要加'/'

(3) 忽略 build/ 目录,但包含 build/src/ 目录

build/     			# 忽略build目录
!build/src/		    #  保留 build/src/ 目录,模式前`加上 ! `来包含那些`被之前规则排除的文件`

(4) 忽略temp/目录和所有.tmp文件:

temp/
*.tmp

(5) output 和 output/ 的区别

  • output:这种写法会忽略名为 output 的文件,无论它位于项目的哪个位置。它不会忽略任何名为 output 的目录
  • output/:这种写法会忽略 output/ 这个目录下的所有内容,包括子目录和文件。它不忽略其他目录或文件名为 output 的文件

简单来说,使用不带斜杠 / 的 output 仅忽略文件,而带斜杠的 output/ 忽略整个目录及其内容

3. 案例

项目的根目录下创建或编辑一个.gitignore文件, 对应的内容如下:

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### PyCharm ###
# User-specific stuff
.idea

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

# JetBrains templates
**___jb_tmp___

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/
docs/build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
#   However, in case of collaboration, if having platform-specific dependencies or dependencies
#   having no cross-platform support, pipenv may install dependencies that don’t work, or not
#   install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim

# Temporary
.netrwhist
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

### Researcher ###
# output
train_log
docs/api
.code-workspace.code-workspace
output                      		# 忽略 output 文件
outputs/						    # 忽略outputs目录
instant_test_output
inference_test_output
*.pkl
*.npy
*.pth
*.bin
*.pickle							# 忽略所有.pickle文件
events.out.tfevents*

# vscode
*.code-workspace
.vscode/       			 			# 忽略 .vscode目录

# vim
.vim/

onnx_models/     					# 忽略onnx_models目录
*.onnx			 					# 忽略所有的.onnx文件

注意事项

  • .gitignore 文件本身需要被添加到版本控制系统中,这样其他开发者才能使用相同的忽略规则。
  • 如果你之前错误地添加了某些文件到版本控制,并且想要从Git的跟踪中移除它们,但保留在本地,可以使用以下命令:
git rm --cached <file>
  • .gitignore 文件的规则是递归的,对所有子目录有效

创建 .gitignore 文件后,你可以使用文本编辑器编辑它,然后将其添加到你的 Git 仓库中。这样,你的团队成员都会遵循相同的文件忽略规则。

标签:文件,忽略,build,使用,output,目录,###,gitignore
From: https://blog.csdn.net/weixin_38346042/article/details/141058379

相关文章

  • Nuxt3 axios封装 使用axios接口请求
    一、先安装axiosnpminstalladdaxios封装请求request.ts文件importaxiosfrom'axios'import{ElMessage,Message}from"element-plus"import{getToken}from'./token.js'constservice=axios.create({baseURL:'/api',//......
  • OpenCV图像滤波(6)高斯滤波函数GaussianBlur()的使用
    操作系统:ubuntu22.04OpenCV版本:OpenCV4.9IDE:VisualStudioCode编程语言:C++11算法描述函数使用高斯滤波器对图像进行模糊处理。该函数使用指定的高斯核对源图像进行卷积。支持原位过滤。高斯模糊是一种有效的图像平滑技术,可以减少图像中的噪声和细节。函数原型vo......
  • 三、Tauri 使用(各种设置)
    1.开启所有API使用{"tauri":{ "allowlist":{  "all":true, }}}2.关闭鼠标右键window.addEventListener('contextmenu',(e)=>e.preventDefault(),false);​//在生成环境关闭鼠标右键if(import.meta.env.MODE==="......
  • 二、Tauri 使用(http请求 axios)
    1.启用该功能        在tauri.conf.json文件中启用该功能,配置要请求的API路径,多个API的情况使用逗号隔开就可以了{ "tauri":{  "allowlist":{   "http":{    "all":true,    "request":true,    "scope":["http:......
  • OpenCV图像滤波(7)cv::getDerivKernels() 函数的使用
    操作系统:ubuntu22.04OpenCV版本:OpenCV4.9IDE:VisualStudioCode编程语言:C++11算法描述函数返回用于计算空间图像导数的滤波系数。该函数计算并返回用于空间图像导数的滤波系数。当ksize=FILTER_SCHARR时,生成Scharr3x3核(参见Scharr)。否则,生成Sobel核(参见Sob......
  • Kubernetes对象YAML文件的基本格式详解
    简介  Kubernetes(K8s)作为云原生时代的基础设施核心,其配置文件通常采用YAML格式来定义和管理各种资源对象。YAML(YAMLAin'tMarkupLanguage)因其简洁、易读和易写的特性,在Kubernetes中得到了广泛应用。本文将详细探讨Kubernetes对象YAML文件的基本格式,重点解析GVK(Group、Ve......
  • php 使用phpoffice/phpword导出word
    安装指令composerrequirephpoffice/phpword 基本设置/***//设置常用文本样式*'size'=>12,//文字大小*'name'=>'宋体',//字体名称*'bold'=>true,//加粗*'italic'......
  • 如何使用 Python 从 Excel 工作表中读取正斜杠
    我有20多列的Excel工作表,如果我想选择不包含文本n/a的行,是否可以将n/a作为文本传递并找到它?我尝试过的代码是,''''将pandas导入为pd进口重新导入操作系统defextract_data(input_file):#读取输入的Excel文件df=pd.read_excel(input_file)#Checkif'......
  • 如何关闭redis的自动清理缓存,声明式事务(含有redis)如何解决,redis setnx锁的使用。
    20240809一、解决redis数据被删除的方案1、发现问题2、解决注意!!二、声明式事务(当有redis的时候)1.先看代码2.@Transactional(rollbackFor=Exception.class)3.如何解决redis在事务里面,如何保证原子性和一致性3.1我们可以用trycatchfinally来实现3.2我们可以让red......
  • Motrix下载器使用教程
    使用浏览器下载通常会有速度慢的问题,需要借助一些下载管理器软件来进行提速,但有的下载器存在广告多、或者需要付费成为会员才能享受高速下载。这里介绍的Motrix是一款无广告、免费、开源的下载软件,目前使用体验不错,使用方法也很简单。下载安装前往官网进行下载:https://motrix.......