iOS项目使用git管理代码.gitignore设置问题

使用Xcode管理代码时,会产生一些文件影响代码同步,比如UserInterfaceState.xcuserstate,需要设置忽略这些文件,在.gitignore文件中可以设置相应的忽略文件。

首先最好有一个空项目(因为已经上传的项目中的文件再设置.gitignore对已上传的文件无效),github、gitlab、码云都可以。将项目克隆到本地。

点击项目,按shift + command + .可以查看隐藏文件,再次可以隐藏。可以看到上图的.git文件。

cd到该项目,创建.gitignore文件。如下图:

打开.gitignore文件将下面代码粘贴进去。

#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.xcuserstate
*.DS_Store
*.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/

# 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
fastlane/test_output

# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

https://github.com/github/gitignore 源代码在这儿,只添加了忽略
*.xcuserstate
*.DS_Store
文件。
修改完保存,将修改后的项目上传就可以了。以后再提交代码就会忽略.xcuserstate和.DS_Store文件了。

如果项目不是空项目,建议先把完整项目备份好,删掉除.git文件夹以外的所有文件,然后上传。最后,再按上面的步骤走一遍,再把备份项目除去.git文件夹和.gitignore文件拷贝进去,再将代码上传就行了。

你可能感兴趣的:(iOS项目使用git管理代码.gitignore设置问题)