开发工具类IOS三人行iOS开发那点儿事

iOS git提交时忽略频繁更新的UserInterfaceSt

2016-07-26  本文已影响6606人  plantseeds

今天提交代码时,一直提示有未提交的文件,发现UserInterfaceState.xcuserstate这个文件一直在自动更新,即使我的代码没改变,提交时也有它。后来百度到这是Xcode自带的文件,不应该被提交到版本管理中
(这篇文张中的一段:iOS开发那些事-Git在Xcode中的配置与使用

其中HelloWorld.xcodeproj属于包文件,它内部的很多东西是不能提交的,包括: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 文件内容可在这里找到Objective-C的,复制下来
github/gitignore

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

先创建touch .gitignore,
打开open .gitignore,
粘贴进去,
保存关闭,
添加到缓存区,git add .gitignore
提交git commit -m "添加了.gitignore文件"
推送git push

这样就配置完成 .gitignore文件,
然后在终端执行前面那3句操作,
再试下提交代码,就没有UserInterfaceState.xcuserstate文件了。

另外

今天用Xcode自带的git合并分支代码到主支,因为这份代码是从网上clone下来的,先是提示uncommunicative...什么的提示,大意是说Xcode和git之间没有交流啥的,百度后,在命令行配置下用户名和邮箱就好了

git config --global user.name xxx
git config --global user.email xxx

但是分支合并到主支时,又提示其他错误:
HelloWorld.xcscheme、xcschememanagement.plist...之类的几个文件有冲突,得先解决冲突,否则无法合并。。真的不知道这几个文件是干啥的啊,百度一番+瞎折腾,反正后来用SourceTree的冲突解决,不知所云的合并成功了。

上一篇下一篇

猜你喜欢

热点阅读