git忽略. DS_Store、UserInterfaceState.xcuserstate和Pods

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

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

解决步骤:

1、打开终端

cd 到工程中.git隐藏文件所在的同级目录,并不是.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
#`eg` git rm --cached QQDemo.xcworkspace/xcuserdata/zxmmac.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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容