如何消除代码提交中UserInterfaceState.xcuserstate和.DS_Store文件
在使用git管理代码中,经常会遇到UserInterfaceState.xcuserstate和.DS_Store更新,导致需要不断进行commit或者discard all change。尤其是UserInterfaceState.xcuserstate文件,几乎是每个几秒就会更新一次,所以异常烦恼。
解决方法
后面通过在网上不断搜索,终于找到解决方法,并亲自实验,结果有效,终于能够不再收到那两个文件的骚扰了,开心~~~。
解决步骤:
- 打开终端;
- cd 到工程中.git隐藏文件所在的目录
- 创建.gitignore文件:touch .gitignore
- 打开.gitignore文件:open .gitignore
- 将以下内容粘贴进去:
# 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
*.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/
#忽略.DS_Store文件
.DS_Store
- 保存关闭
- 添加到缓存区:git add .gitignore;
- 提交git commit -m “添加了.gitignore文件”
- 推送git push;
- 处理UserInterfaceState.xcuserstate,输入以下命名:
git rm --cached [YourProjectName].xcworkspace/xcuserdata/[YourUsername].xcuserdatad/UserInterfaceState.xcuserstate
git commit -m "Removed file that shouldn't be tracked"
git push
- 处理.DS_Store:
//删除原有的.DS_Store
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
//提交
git commit -m "去除.DS_Store文件"
git push
至此,UserInterfaceState.xcuserstate和.DS_Store文件问题就被解决掉了。
在此感谢以下链接中的作者提供解决方法:
[1]: https://www.jianshu.com/p/6f464f555f2d
[2]: https://blog.csdn.net/nunchakushuang/article/details/50511765