现在项目一般都是用git
来进行版本管理,但是日常开发中,并不是所有项目中的文件都需要进行版本管理,例如iOS开发中的Pod
文件,又或者是一些测试资源等等.此时就需要配置.gitignore
来忽略这些文件.
创建gitignore文件
mac
显示隐藏文件,打开终端:(非必须步骤,因为gitignore文件是隐藏的,此方法用来显示出gitignore文件)
// 显示
defaults write com.apple.finder AppleShowAllFiles -bool true
// 隐藏
defaults write com.apple.finder AppleShowAllFiles -bool false
调用上面命令后,不会立即生效,我们还需要重启Finder
,如下步骤
点击mac
右上角苹果图标 -> 强制退出 -> Finder
(重新开启)
我们先显示隐藏文件,终端进入项目主目录,使用命令创建gitignore
文件:
// 创建
touch .gitignore
// 打开
open .gitignore
到这里gitignore
文件就创建好了.
gitignore语法
#
: 注释/
: 过滤整个文件夹
// 过滤掉整个Pod文件夹
Pod/
*
: 通配符
// 过滤掉所有.swift为后缀的文件
*.swift
- 过滤具体文件
demo.png
!
: 不过滤
*.swift
// 不过滤这个文件
!need.swift
提供的swift中使用的gitignore文件
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
// 忽略文件夹
build/
DerivedData/
## Various settings
// 忽略后缀为.pbxuser文件
*.pbxuser
!default.pbxuser
*.mode1v3
// 不忽略default.mode1v3文件
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint
## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
## Playgrounds
timeline.xctimeline
playground.xcworkspace
# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
.build/
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Build
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control
// 忽略具体
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output