很久以前,幾位剛開始學習 iOS 開發的朋友迎來了他們的第一次合作,這是他們第一次使用 git,在他們使用git共同開發的過程裡一直產生各種 conflicts,甚至只是打開 Storyboard 就產生了conglicts,他們索性根據分工,將開發檔案分成了多個 Storyboard,並約定不要打開別人的檔案……Orz
不過他們也很順利的在一個月內完成了他們的小項目,當然後來就是使用 .gitignore 來處理這個問題了。
當我們在使用 Xcode 開發的時候,其實都會使 Xcode UserInterfaceState.xcuserstate 產生變化,所以我們需要讓 git 忽略掉 .xcuserstate 這個文件。
我們也可以偷懶一點,直接使用 gitignore.io 生成 .gitignore 文件內容。
只要輸入你使用的語言,就可以直接生成一份 .gitignore 文件,而忽略的內容基本上有做註釋。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# Created by https://www.gitignore.io/api/swift ### Swift ### # 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 *.xcuserstate ## Obj-C/Swift specific *.hmap *.ipa *.dSYM.zip *.dSYM ## Playgrounds timeline.xctimeline playground.xcworkspace # Swift Package Manager # # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. # Packages/ .build/ # 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://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md fastlane/report.xml fastlane/Preview.html fastlane/screenshots fastlane/test_output # End of https://www.gitignore.io/api/swift |
正在開發的Project
如果是正在開發的 Project,可以通過 git rm 來拿掉 xcuserstate。
下面有個來自 slackoverflow 的例子,ProjectFolder 是項目名稱,myUserName 是你電腦的 user name。
1 2 |
git rm --cached ProjectFolder.xcodeproj/project.xcworkspace/xcuserdata/myUserName.xcuserdatad/UserInterfaceState.xcuserstate git commit -m "Removed file that shouldn't be tracked" |
不知道怎麼加入一個 .gitignore文件?
可以參考鳥哥的vi文書處理教學。
喔對,如果你是用 windows 就不是這樣操作了,但你應該不會是用windows在開發 iOS App 吧?= =
小分享,這樣處理xcuserstate更方便:
git rm –cached *.xcuserstate
git commit -m “Removed file that shouldn’t be tracked”
,這樣就可以無腦解決,不然有沒有用cocoaPod路徑也不同啊XD
感謝經驗分享~!!