问题描述:
在xcode开发app中,通过设置将DerivedData和build两个文件夹显示到了工程路径下了
在每次经过改动和编译后,这两个文件夹里边的内容都会变动,git没有任何设置情况下,会追踪所有的变动,但这些追踪没什么意义,他们是临时生成的或经过编译生成的
有没有办法让 git 不追踪这两个文件夹?
解决:
- 在project创建并git init之后,在.git同级目录下touch一个文件.gitignore
- GitHub已经为我们准备了各种配置文件,根据自己的开发语言和平台等,可单独使用或组合使用
- 将编辑好的配置文件内容,写入到.gitignore中,保存
- git add .gitignore,git commit -m 'add git ignore'
必须确保.gitignore是第一个被add的,是第一个被commit的。设置以后,git就不追踪这些在.gitignore中过虑过的文档了
.gitignore
只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore
是无效的
解决方法就是先把本地缓存删除(改变成未track状态),然后再提交:
git rm -r --cached .
git add .
git commit -m "msg"
.gitignore语法:
- 所有空行或者以注释符号 # 开头的行都会被 Git 忽略
- 可以使用标准的 glob 模式匹配
- 匹配模式最后跟斜杠(/)说明要忽略的是目录
- 要忽略指定模式以外的文件或目录,可以在模式前加上感叹号(!)进行取
glob 模式是指 shell 所使用的简化了的正则表达式,简单的匹配规则这这样的:
"*"
:星号匹配零个或多个任意字符[]
:匹配任何一个列在方括号中的字符,如[ab]匹配a或者匹配b"?"
:问号匹配一个任意字符[n-m]
:匹配所有在这两个字符范围内的字符,如[0-9]表示匹配所有0到9的数字
示例:
build/
:忽略当前路径下的build目录,包含build下的所有子目录和文件/logs.txt
:忽略根目录下的logs.txt文件*.html
:忽略所有后缀为.html的文件!/classes/a.txt
:不忽略classes目录下的a.txt文件tmp/*.txt
:只忽略tmp目录下的.txt文件**/foo
:可以忽略/foo, a/foo, a/b/foo等
如果你打算把仓库共享给其他人,但是又不想让其他人忽略这个文件,或者得知这个文件的名字,可以写到 .git/info/exclude 文件里去。
xcode project中配置的.gitignore内容:
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## User settings
xcuserdata/
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
## Obj-C/Swift specific
*.hmap
## App packaging
*.ipa
*.dSYM.zip
*.dSYM
# 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/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace
# 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/**/*.png
fastlane/test_output
# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode
iOSInjectionProject/