使用Xcode管理代碼時,會產(chǎn)生一些文件影響代碼同步,比如UserInterfaceState.xcuserstate,需要設(shè)置忽略這些文件,在.gitignore文件中可以設(shè)置相應(yīng)的忽略文件。
首先最好有一個空項(xiàng)目(因?yàn)橐呀?jīng)上傳的項(xiàng)目中的文件再設(shè)置.gitignore對已上傳的文件無效),github、gitlab、碼云都可以。將項(xiàng)目克隆到本地。
WX20180124-113612@2x.png
點(diǎn)擊項(xiàng)目,按shift + command + .可以查看隱藏文件,再次可以隱藏??梢钥吹缴蠄D的.git文件。
cd到該項(xiàng)目,創(chuàng)建.gitignore文件。如下圖:
WX20180124-114924@2x.png
打開.gitignore文件將下面代碼粘貼進(jìn)去。
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
build/
DerivedData/
## Various settings
*.xcuserstate
*.DS_Store
*.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
fastlane/test_output
# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode
iOSInjectionProject/
https://github.com/github/gitignore 源代碼在這兒,只添加了忽略
*.xcuserstate
*.DS_Store
文件。
修改完保存,將修改后的項(xiàng)目上傳就可以了。以后再提交代碼就會忽略.xcuserstate和.DS_Store文件了。
如果項(xiàng)目不是空項(xiàng)目,建議先把完整項(xiàng)目備份好,刪掉除.git文件夾以外的所有文件,然后上傳。最后,再按上面的步驟走一遍,再把備份項(xiàng)目除去.git文件夾和.gitignore文件拷貝進(jìn)去,再將代碼上傳就行了。