前言
在現(xiàn)代的軟件開(kāi)發(fā)行業(yè)當(dāng)中,一個(gè)沒(méi)有版本控制系統(tǒng)的軟件工程是不可想象的,一個(gè)沒(méi)有熟練掌握版本控制工具的軟件工程師是不可雇傭的(霧).在眾多類(lèi)型的版本控制系統(tǒng)當(dāng)中, Git 因其強(qiáng)大的靈活性和速度,從誕生伊始就迅速躥紅.然鵝,正如任何一枚硬幣都有兩面, Git 的缺點(diǎn)和其優(yōu)點(diǎn)一樣明顯.
Git的設(shè)計(jì)讓使用者覺(jué)得自己比想像中的笨。
-- Andrew Morton(Linux核心開(kāi)發(fā)者)
通常情況下, 想要完全掌握 Git 的所有使用要領(lǐng)和設(shè)計(jì)內(nèi)涵,所需要花費(fèi)的周期較長(zhǎng).在學(xué)習(xí) Git 的這條道路上也不可避免的會(huì)產(chǎn)生一些誤解和誤用(沒(méi)有為整個(gè)工程合理地配置.gitignore文件就是其中一項(xiàng)).
配置建議
一般我們總會(huì)有些文件無(wú)需納入 Git 的管理,也不希望它們總出現(xiàn)在未跟蹤文件列表。 通常都是些自動(dòng)生成的文件,比如日志文件,或者編譯過(guò)程中創(chuàng)建的臨時(shí)文件等。 在這種情況下,我們可以創(chuàng)建一個(gè)名為 .gitignore 的文件,列出要忽略的文件模式。下面列出的是 iOS 開(kāi)發(fā)者在日常使用 Git 進(jìn)行項(xiàng)目的版本控制時(shí),所應(yīng)該進(jìn)行的 .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/
必要性
關(guān)于配置Git的.gitignore文件的必要性,可參見(jiàn) Git 的官方指導(dǎo)手冊(cè)的基礎(chǔ)內(nèi)容 Git-基礎(chǔ)-記錄每次更新到倉(cāng)庫(kù)
資源
更多的語(yǔ)言的 .gitignore文件配置參見(jiàn) GitHub 官方網(wǎng)站的倉(cāng)庫(kù),倉(cāng)庫(kù)地址為 https://github.com/github/gitignore
附言
Git 幾乎是為管理純文本文件而生的,它天然的就不適合管理圖片和音頻視頻等媒體資源.所以在進(jìn)行實(shí)際的軟件開(kāi)發(fā)工作時(shí),請(qǐng)盡量不要添加較大體積的圖片和音視頻文件,因?yàn)樵谀闾砑恿诉@些媒體資源而之后又頻繁改動(dòng),很容易就造成了整個(gè)由 Git 進(jìn)行管理的軟件項(xiàng)目的體積迅速膨脹.