# IOS專案 使用git 忽略文件方法 >[name=Eve] [time=Thu, Dec 12, 2019] ###### tags: `git` `IOS` `ignore` <br/> > git版本控制是絕大多數的工程師會使用的,但有些檔案若不想放在git裡面一起備份,只要在專案目錄裡放一個 `.gitignore` 檔案,並且設定想要忽略的規則就行了。 > ## :rocket: 解決方法: ### Step 1: 打開終端機,切換到專案資料夾下 ```objectivec= $ cd projectName $ ls -a //查看隱藏檔案 ```  ### Step 2: 建立 `.gitignore`檔案 ```objectivec= $ vim .gitignore ``` ### Step 3: 輸入`i` 進入編輯模式 ``` -- insert-- ``` ### Step 4: 貼入以下內容,為需忽略的檔案(可自行調整) ```json= # 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 # # 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/ ``` ### Step 5: 建立完成後,輸入指令確認是否有該檔案 ```objectivec= git status ```  ### Step 6: 上傳至github/gitlab ```objectivec= git add . git commit -m "ignore file" git push ``` ### Step 7: 若要忽略的檔案先前已被git追蹤,則須先清除緩存在更新文件 ```objectivec= git rm -r --cached . git add . git commit -m 'update .gitignore' ``` <br/> <div style="text-align: center"> <img src="https://i.imgur.com/IUnlzHF.png"/> </div> <br/> ## 參考文件 [iOS工程配置git忽略文件](https://juejin.im/post/5c05e612f265da616d53f37e )
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up