.gitignore忽略 Objective-C中的哪些文件不被git"跟踪"

.gitignore忽略文件地址下载

通常我们在多人开发中使用git进行源代码管理的时候,创建完远程共享版本库,第一步就是创建.gitignore的忽略文件,先commit,然后在创建项目文件,开始进行提交项目,这时候的提交就会过滤了一些不必要的文件.我们称之为"忽略文件"
github总有大牛为我们已经写好了所有的忽略文件,下面为你解析一些读懂这些规则

# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated 忽略build/目录下的所有文件
build/
# 忽略DerivedData/目录下的所有文件
DerivedData/

## Various settings 各种各样的设置
# 忽略所有 .pbxuser 结尾的文件
*.pbxuser
# 但 default.pbxuser 除外
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

# 忽略xcuserdata目录下的所有文件
xcuserdata/

## Other
*.moved-aside
*.xcuserstate

## Obj-C/Swift specific
*.hmap
*.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/

# 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://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md

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

# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

下面对这些常用的规则进行一下总结:

忽略文件

  • /file/ 过滤file整个文件夹
  • /file/ 过滤file目录下的所有文件
  • /file/xxx.tex 过滤某个具体文件
  • *.xxx 顾虑所有的以.xxx为结尾的文件
    含义: 被过滤掉的文件就不会出现在你的GitHub库中了,当然本地库中还有,只是push的时候不会上传

gitignore还可以指定要将哪些文件添加到版本管理中

Git会将满足这类规则的文件添加到版本管理中

  • !*.txt
  • !/file/test.txt

最后一些友情的提示:

  • 最后需要强调的一点是,如果你不慎在创建.gitignore文件之前就push了项目,那么即使你在.gitignore文件中写入新的过滤规则,这些规则也不会起作用,Git仍然会对所有文件进行版本管理。

  • 简单来说,出现这种问题的原因就是Git已经开始管理这些文件了,所以你无法再通过过滤规则过滤它们。

  • 所以大家一定要养成在项目开始就创建.gitignore文件的习惯,否则一旦push,处理起来会非常麻烦。

你可能感兴趣的:(.gitignore忽略 Objective-C中的哪些文件不被git"跟踪")