当Git与Xcode一起使用时,我应该在.gitignore中包含哪些文件?


当前回答

我使用以下在gitignore.io中生成的.gitignore文件:

### Xcode ###
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.xcuserstate


### Objective-C ###
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
Pods/

其他回答

关于“build”目录排除-

如果您将构建文件放在与源文件不同的目录中,就像我所做的那样,您不必担心树中的文件夹。

这也使得共享代码变得更加简单,防止臃肿的备份,甚至当你依赖于其他Xcode项目时(同时要求构建彼此位于相同的目录中)。

你可以从Github gist https://gist.github.com/708713获取最新的拷贝

我当前的。gitignore文件是

# Mac OS X
*.DS_Store

# Xcode
*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3
*.xcuserstate
project.xcworkspace/
xcuserdata/

# Generated files
*.o
*.pyc


#Python modules
MANIFEST
dist/
build/

# Backup files
*~.nib

大多数答案都来自Xcode 4-5时代。我建议使用现代风格的ignore文件。

# Xcode Project
**/*.xcodeproj/xcuserdata/
**/*.xcworkspace/xcuserdata/
**/.swiftpm/xcode/xcuserdata/
**/*.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
**/*.xcworkspace/xcshareddata/*.xccheckout
**/*.xcworkspace/xcshareddata/*.xcscmblueprint
**/*.playground/**/timeline.xctimeline
.idea/

# Build
Scripts/build/
build/
DerivedData/
*.ipa

# Carthage
Carthage/

# CocoaPods
Pods/

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/sign&cert

# CSV
*.orig
.svn

# Other
*~
.DS_Store
*.swp
*.save
._*
*.bak

请从https://github.com/BB9z/iOS-Project-Template/blob/master/.gitignore更新

以下是GitHub默认用于新Xcode存储库的.gitignore:

https://github.com/github/gitignore/blob/master/Objective-C.gitignore

它可能在任何给定的时间都是合理正确的。

对于Xcode 4,我还添加了:

YourProjectName.xcodeproj/xcuserdata/*
YourProjectName.xcodeproj/project.xcworkspace/xcuserdata/*

我补充说:

xcuserstate
xcsettings

并将我的.gitignore文件放在项目的根目录下。

在承诺和推动之后。然后我跑了起来:

git rm --cached UserInterfaceState.xcuserstate WorkspaceSettings.xcsettings

埋藏在下面的文件夹:

<my_project_name>/<my_project_name>.xcodeproj/project.xcworkspace/xcuserdata/<my_user_name>.xcuserdatad/

然后我再次运行git commit和push