消除UserInterfaceState.xcuserstate和.DS_Store文件

如何消除代码提交中UserInterfaceState.xcuserstate和.DS_Store文件

在使用git管理代码中,经常会遇到UserInterfaceState.xcuserstate和.DS_Store更新,导致需要不断进行commit或者discard all change。尤其是UserInterfaceState.xcuserstate文件,几乎是每个几秒就会更新一次,所以异常烦恼。

解决方法

后面通过在网上不断搜索,终于找到解决方法,并亲自实验,结果有效,终于能够不再收到那两个文件的骚扰了,开心~~~。

解决步骤:

  1. 打开终端;
  2. cd 到工程中.git隐藏文件所在的目录
  3. 创建.gitignore文件:touch .gitignore
  4. 打开.gitignore文件:open .gitignore
  5. 将以下内容粘贴进去:
# 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
  1. 保存关闭
  2. 添加到缓存区:git add .gitignore;
  3. 提交git commit -m “添加了.gitignore文件”
  4. 推送git push;
  5. 处理UserInterfaceState.xcuserstate,输入以下命名:
git rm --cached [YourProjectName].xcworkspace/xcuserdata/[YourUsername].xcuserdatad/UserInterfaceState.xcuserstate

git commit -m "Removed file that shouldn't be tracked"

git push
  1. 处理.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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值