为你的 Git 添加 .gitignore 配置

2018-05-30  本文已影响91人  金银岛

前言

在现代的软件开发行业当中,一个没有版本控制系统的软件工程是不可想象的,一个没有熟练掌握版本控制工具的软件工程师是不可雇佣的(雾).在众多类型的版本控制系统当中, Git 因其强大的灵活性和速度,从诞生伊始就迅速蹿红.然鹅,正如任何一枚硬币都有两面, Git 的缺点和其优点一样明显.

Git的设计让使用者觉得自己比想像中的笨。
-- Andrew Morton(Linux核心开发者)

通常情况下, 想要完全掌握 Git 的所有使用要领和设计内涵,所需要花费的周期较长.在学习 Git 的这条道路上也不可避免的会产生一些误解和误用(没有为整个工程合理地配置.gitignore文件就是其中一项).

配置建议

一般我们总会有些文件无需纳入 Git 的管理,也不希望它们总出现在未跟踪文件列表。 通常都是些自动生成的文件,比如日志文件,或者编译过程中创建的临时文件等。 在这种情况下,我们可以创建一个名为 .gitignore 的文件,列出要忽略的文件模式。下面列出的是 iOS 开发者在日常使用 Git 进行项目的版本控制时,所应该进行的 .gitignore 的基本配置.

# Xcode

#

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

## Build generated

build/

DerivedData/

## Various settings

*.pbxuser

!default.pbxuser

*.mode1v3

!default.mode1v3

*.mode2v3

!default.mode2v3

*.perspectivev3

!default.perspectivev3

xcuserdata/

## Other

*.moved-aside

*.xccheckout

*.xcscmblueprint

## 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://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/

必要性

关于配置Git.gitignore文件的必要性,可参见 Git 的官方指导手册的基础内容 Git-基础-记录每次更新到仓库

资源

更多的语言的 .gitignore文件配置参见 GitHub 官方网站的仓库,仓库地址为 https://github.com/github/gitignore

附言

Git 几乎是为管理纯文本文件而生的,它天然的就不适合管理图片和音频视频等媒体资源.所以在进行实际的软件开发工作时,请尽量不要添加较大体积的图片和音视频文件,因为在你添加了这些媒体资源而之后又频繁改动,很容易就造成了整个由 Git 进行管理的软件项目的体积迅速膨胀.

上一篇 下一篇

猜你喜欢

热点阅读