Git 忽略文件.gitignore

2018-08-03  本文已影响0人  MeteorCode

.gitignore

记录顺序:

一、.gitignore文件

touch .gitignore
vim .gitignore 
# Xcode
.DS_Store

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcworkspace
!default.xcworkspace

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

# CocoaPods
Pods
!Podfile
!Podfile.lock

# Carthage
Carthage/Build

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output

# Code Injection
iOSInjectionProject/

生成配置的网站

gitignore.io

gitignore.io.png

在网站上输入Objective-C和Swift会生成一份配置;


配置.png

参考资源:
https://bingozb.github.io/37.html
https://www.cnblogs.com/haiq/archive/2012/12/26/2833746.html
https://www.cnblogs.com/kevingrace/p/5690241.html

二、两种过滤模式

.gitignore文件过滤有两种模式:

1- 开放模式

build/
*.ipa
fastlane/report.xml  
fastlane/*    //fastlane目录下的所有内容,包括子目录;
/fastlane/*   //根目录下,/fastlane/目录的所有内容;

2- 保守模式

!Podfile
!src/
fastlane/*  //注意:文件夹后要加上/*,否则无法实现效果;
!fastlane/report.xml

三、通配符

*.log  
demo_1?.txt 
demo[0-9]  //匹配0~9的单个字符;
demo[^0-9]  //匹配除去0~9的单个字符

四、已提交到远程的文件,想忽略它

git rm -r --cached . 
git add .
git commit -m "更新gitignore文件"
git push origin master

清除单个文件的缓存:

git rm --cached <文件>

.gitkeep的作用

Git无法追踪一个空文件夹

# .gitignore 
work/*
!.gitkeep

Git忽略work文件夹下,除.gitkeep外的所有文件;
Git就可以实现追踪空文件夹;

上一篇 下一篇

猜你喜欢

热点阅读