今天提交代碼時睬辐,一直提示有未提交的文件挠阁,發(fā)現(xiàn)UserInterfaceState.xcuserstate這個文件一直在自動更新宾肺,即使我的代碼沒改變,提交時也有它侵俗。后來百度到這是Xcode自帶的文件锨用,不應(yīng)該被提交到版本管理中
(這篇文張中的一段:iOS開發(fā)那些事-Git在Xcode中的配置與使用)
其中HelloWorld.xcodeproj屬于包文件,它內(nèi)部的很多東西是不能提交的隘谣,包括:project.xcworkspace和xcuserdata黔酥,它們是與用戶有關(guān)的。Git中有一個.gitignore配置文件洪橘,在這個文件中可以設(shè)置被忽略的文件。
后來百度到棵帽,在終端鍵入下面3句熄求,可以在提交代碼時忽略掉UserInterfaceState.xcuserstate文件
git rm --cached [YourProjectName].xcworkspace/xcuserdata/[YourUsername].xcuserdatad/UserInterfaceState.xcuserstate
git commit -m "Removed file that shouldn't be tracked"
git push
但前提是:
得先在工程目錄(和.git倉庫同路徑的目錄下)配置有 .gitignore 文件,它才能生效逗概!我今晚就入了這個坑弟晚,因為沒配置 .gitignore文件,這3句代碼一直無效逾苫。
This helped me: 1) quit xcode; 2) go to the project directory and do an "ls -la" from the terminal app to make sure you see the .git and .gitignore files; 3) change "ProjectFolder" in the example above to the name of your project; 4) do the two git commands that matt shows; 5) Relaunch XCode and do a commit and verify that the xcuserstate file is no longer listed.
詳情見此文:Can't ignore UserInterfaceState.xcuserstate
配置的 .gitignore 文件內(nèi)容可在這里找到Objective-C的卿城,復(fù)制下來
:github/gitignore
然后,在.git同目錄的命令行下
先創(chuàng)建touch .gitignore铅搓,
打開open .gitignore瑟押,
粘貼進去,
保存關(guān)閉星掰,
添加到緩存區(qū)多望,git add .gitignore
提交git commit -m "添加了.gitignore文件"
推送git push
這樣就配置完成 .gitignore文件,
然后在終端執(zhí)行前面那3句操作氢烘,
再試下提交代碼怀偷,就沒有UserInterfaceState.xcuserstate文件了。
另外
今天用Xcode自帶的git合并分支代碼到主支播玖,因為這份代碼是從網(wǎng)上clone下來的椎工,先是提示uncommunicative...什么的提示,大意是說Xcode和git之間沒有交流啥的蜀踏,百度后维蒙,在命令行配置下用戶名和郵箱就好了
git config --global user.name xxx
git config --global user.email xxx
但是分支合并到主支時,又提示其他錯誤:
HelloWorld.xcscheme果覆、xcschememanagement.plist...之類的幾個文件有沖突木西,得先解決沖突,否則無法合并随静。八千。真的不知道這幾個文件是干啥的啊吗讶,百度一番+瞎折騰,反正后來用SourceTree的沖突解決恋捆,不知所云的合并成功了照皆。