如何消除代码提交中UserInterfaceState.xcuserstate和.DS_Store文件
在使用git管理代码中,经常会遇到UserInterfaceState.xcuserstate
和.DS_Store
更新,导致需要不断进行commit
或者discard all changes
。尤其是UserInterfaceState.xcuserstate
文件,几乎是每个几秒就会更新一次,所以异常烦恼。
解决步骤:
1、打开终端
cd
到工程中.git
隐藏文件所在的目录
如果没有.gitignore
文件
a)创建.gitignore
文件:touch .gitignore
b)打开.gitignore
文件:open .gitignore
有的话也可以直接 vim .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
如果需要忽略Pods
内容,将上面的#Pods/
前的#
去掉
保存关闭.gitignore
2、添加到缓存区:
git add .gitignore`
git commit -m “add .gitignore file”
git push
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
其中[YourProjectName]
是项目名
,[YourUsername]
是用户名(电脑的用户名)
,另外如果提示
fatal: pathspec '[YourProjectName].xcworkspace/xcuserdata/[YourUsername].xcuserdatad/UserInterfaceState.xcuserstate' did not match any files
可能是你所在的目录并不是项目的目录,需要进入'[YourProjectName].xcworkspace
所在的目录操作
4 、处理.DS_Store:
//删除原有的.DS_Store
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
//提交
git commit -m "Remove .DS_Store files"
git push
注意,这一步如果没有成功,需要进入.git
所在的目录下操作。
最后,以上执行命令,一般不会出问题,出现问题大多是由于操作时,所在的目录不正确导致,仔细确认检查目录结构。
原文链接:https://blog.csdn.net/qq_29962929/article/details/90901018