iOS工程配置git忽略檔案(.gitignore) .gitignore無效解決辦法
- 開啟終端cd到本地倉庫,和.git同層(檢視隱藏檔案)
$ cd project $ ls -a 複製程式碼
- 建立.gitignore檔案
$ vim .gitignore 複製程式碼
- 鍵入 "i",看到下面這個,進入編輯模式
-- INSERT -- 複製程式碼
- 把下面的這些複製進去
# 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/ *.xcuserstate ## Other *.moved-aside *.xccheckout *.xcscmblueprint ## Obj-C/Swift specific *.hmap *.ipa *.dSYM.zip *.dSYM # CocoaPods/">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/ 複製程式碼
- 鍵入 "esc" ,退出編輯模式
- 鍵入 ":wq" ,儲存並退出
到這裡,就建立好了".gitignore"檔案了!!
建立完以後發現未生效,因為.gitignore只能忽略那些原來沒有被追蹤的檔案,如果某些檔案已經被納入了版本管理中,則修改.gitignore是無效的
- gitignore規則不生效的解決辦法,先把本地快取刪除然後更新
git rm -r --cached . git add . git commit -m 'update .gitignore' 複製程式碼