iOS git提交時忽略頻繁更新的UserInterfaceState.xcuserstate文件

<pre>

今天提交代碼時,一直提示有未提交的文件,發(fā)現(xiàn)UserInterfaceState.xcuserstate這個文件一直在自動更新,即使我的代碼沒改變,提交時也有它。后來百度到這是Xcode自帶的文件,不應該被提交到版本管理中
(這篇文張中的一段:iOS開發(fā)那些事-Git在Xcode中的配置與使用

其中HelloWorld.xcodeproj屬于包文件,它內(nèi)部的很多東西是不能提交的,包括:project.xcworkspace和xcuserdata,它們是與用戶有關的。Git中有一個.gitignore配置文件,在這個文件中可以設置被忽略的文件。

后來百度到,在終端鍵入下面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的,復制下來
github/gitignore

然后,在.git同目錄的命令行下

先創(chuàng)建touch .gitignore,
打開open .gitignore,
粘貼進去,
保存關閉,
添加到緩存區(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的沖突解決,不知所云的合并成功了。

作者:小風過街
鏈接:http://www.itdecent.cn/p/6f464f555f2d
來源:簡書
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請注明出處。</pre>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容