xcode Git忽略Xcode项目的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:55:05  来源:igfitidea点击:

Git ignore file for Xcode projects

xcodegitmacosversion-controlgitignore

提问by Hagelin

Which files should I include in .gitignorewhen using Gitin conjunction with Xcode?

.gitignoreGitXcode结合使用时应该包含哪些文件?

采纳答案by Adam

I was previously using the top-voted answer, but it needs a bit of cleanup, so here it is redone for Xcode 4, with some improvements.

我之前使用的是最高投票的答案,但它需要一些清理,因此这里针对 Xcode 4 重做,并进行了一些改进。

I've researched everyfile in this list, but several of them do not exist in Apple's official Xcode documentation, so I had to go on Apple mailing lists.

我已经研究了这个列表中的每个文件,但其中一些文件在 Apple 的官方 Xcode 文档中不存在,所以我不得不去 Apple 邮件列表。

Apple continues to add undocumented files, potentially corrupting our live projects. This IMHO is unacceptable, and I've now started logging bugs against it each time they do so. I know they don't care, but maybe it'll shame one of them into treating developers more fairly.

Apple 继续添加未记录的文件,这可能会破坏我们的实时项目。这个恕我直言是不可接受的,我现在已经开始记录每次他们这样做的错误。我知道他们不在乎,但也许让他们中的一个人更公平地对待开发人员会感到羞耻。



If you need to customize, here's a gist you can fork: https://gist.github.com/3786883

如果您需要自定义,这里有一个可以 fork 的要点:https: //gist.github.com/3786883



#########################
# .gitignore file for Xcode4 and Xcode5 Source projects
#
# Apple bugs, waiting for Apple to fix/respond:
#
#    15564624 - what does the xccheckout file in Xcode5 do? Where's the documentation?
#
# Version 2.6
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2015 updates:
# - Fixed typo in "xccheckout" line - thanks to @lyck for pointing it out!
# - Fixed the .idea optional ignore. Thanks to @hashier for pointing this out
# - Finally added "xccheckout" to the ignore. Apple still refuses to answer support requests about this, but in practice it seems you should ignore it.
# - minor tweaks from Jona and Coeur (slightly more precise xc* filtering/names)
# 2014 updates:
# - appended non-standard items DISABLED by default (uncomment if you use those tools)
# - removed the edit that an SO.com moderator made without bothering to ask me
# - researched CocoaPods .lock more carefully, thanks to Gokhan Celiker
# 2013 updates:
# - fixed the broken "save personal Schemes"
# - added line-by-line explanations for EVERYTHING (some were missing)
#
# NB: if you are storing "built" products, this WILL NOT WORK,
# and you should use a different .gitignore (or none at all)
# This file is for SOURCE projects, where there are many extra
# files that we want to exclude
#
#########################

#####
# OS X temporary files that should never be committed
#
# c.f. http://www.westwind.com/reference/os-x/invisibles.html

.DS_Store

# c.f. http://www.westwind.com/reference/os-x/invisibles.html

.Trashes

# c.f. http://www.westwind.com/reference/os-x/invisibles.html

*.swp

#
# *.lock - this is used and abused by many editors for many different things.
#    For the main ones I use (e.g. Eclipse), it should be excluded
#    from source-control, but YMMV.
#   (lock files are usually local-only file-synchronization on the local FS that should NOT go in git)
# c.f. the "OPTIONAL" section at bottom though, for tool-specific variations!
#
# In particular, if you're using CocoaPods, you'll want to comment-out this line:
*.lock


#
# profile - REMOVED temporarily (on double-checking, I can't find it in OS X docs?)
#profile


####
# Xcode temporary files that should never be committed
# 
# NB: NIB/XIB files still exist even on Storyboard projects, so we want this...

*~.nib


####
# Xcode build files -
#
# NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "DerivedData"

DerivedData/

# NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "build"

build/


#####
# Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups)
#
# This is complicated:
#
# SOMETIMES you need to put this file in version control.
# Apple designed it poorly - if you use "custom executables", they are
#  saved in this file.
# 99% of projects do NOT use those, so they do NOT want to version control this file.
#  ..but if you're in the 1%, comment out the line "*.pbxuser"

# .pbxuser: http://lists.apple.com/archives/xcode-users/2004/Jan/msg00193.html

*.pbxuser

# .mode1v3: http://lists.apple.com/archives/xcode-users/2007/Oct/msg00465.html

*.mode1v3

# .mode2v3: http://lists.apple.com/archives/xcode-users/2007/Oct/msg00465.html

*.mode2v3

# .perspectivev3: http://stackoverflow.com/questions/5223297/xcode-projects-what-is-a-perspectivev3-file

*.perspectivev3

#    NB: also, whitelist the default ones, some projects need to use these
!default.pbxuser
!default.mode1v3
!default.mode2v3
!default.perspectivev3


####
# Xcode 4 - semi-personal settings
#
# Apple Shared data that Apple put in the wrong folder
# c.f. http://stackoverflow.com/a/19260712/153422
#     FROM ANSWER: Apple says "don't ignore it"
#     FROM COMMENTS: Apple is wrong; Apple code is too buggy to trust; there are no known negative side-effects to ignoring Apple's unofficial advice and instead doing the thing that actively fixes bugs in Xcode
# Up to you, but ... current advice: ignore it.
*.xccheckout

#
#
# OPTION 1: ---------------------------------
#     throw away ALL personal settings (including custom schemes!
#     - unless they are "shared")
# As per build/ and DerivedData/, this ought to have a trailing slash
#
# NB: this is exclusive with OPTION 2 below
xcuserdata/

# OPTION 2: ---------------------------------
#     get rid of ALL personal settings, but KEEP SOME OF THEM
#     - NB: you must manually uncomment the bits you want to keep
#
# NB: this *requires* git v1.8.2 or above; you may need to upgrade to latest OS X,
#    or manually install git over the top of the OS X version
# NB: this is exclusive with OPTION 1 above
#
#xcuserdata/**/*

#     (requires option 2 above): Personal Schemes
#
#!xcuserdata/**/xcschemes/*

####
# Xcode 4 workspaces - more detailed
#
# Workspaces are important! They are a core feature of Xcode - don't exclude them :)
#
# Workspace layout is quite spammy. For reference:
#
# /(root)/
#   /(project-name).xcodeproj/
#     project.pbxproj
#     /project.xcworkspace/
#       contents.xcworkspacedata
#       /xcuserdata/
#         /(your name)/xcuserdatad/
#           UserInterfaceState.xcuserstate
#     /xcshareddata/
#       /xcschemes/
#         (shared scheme name).xcscheme
#     /xcuserdata/
#       /(your name)/xcuserdatad/
#         (private scheme).xcscheme
#         xcschememanagement.plist
#
#

####
# Xcode 4 - Deprecated classes
#
# Allegedly, if you manually "deprecate" your classes, they get moved here.
#
# We're using source-control, so this is a "feature" that we do not want!

*.moved-aside

####
# OPTIONAL: Some well-known tools that people use side-by-side with Xcode / iOS development
#
# NB: I'd rather not include these here, but gitignore's design is weak and doesn't allow
#     modular gitignore: you have to put EVERYTHING in one file.
#
# COCOAPODS:
#
# c.f. http://guides.cocoapods.org/using/using-cocoapods.html#what-is-a-podfilelock
# c.f. http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
#!Podfile.lock
#
# RUBY:
#
# c.f. http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
#
#!Gemfile.lock
#
# IDEA:
#
# c.f. https://www.jetbrains.com/objc/help/managing-projects-under-version-control.html?search=workspace.xml
# 
#.idea/workspace.xml
#
# TEXTMATE:
#
# -- UNVERIFIED: c.f. http://stackoverflow.com/a/50283/153422
#
#tm_build_errors

####
# UNKNOWN: recommended by others, but I can't discover what these files are
#

回答by Hagelin

Based on this guide for Mercurialmy .gitignore includes:

基于这个 Mercurial 指南,我的 .gitignore 包括:

.DS_Store
*.swp
*~.nib

build/

*.pbxuser
*.perspective
*.perspectivev3

I've also chosen to include:

我还选择包括:

*.mode1v3
*.mode2v3

which, according to this Apple mailing list post, are "user-specific project settings".

根据此 Apple 邮件列表帖子,其中是“特定于用户的项目设置”。

And for Xcode 4:

对于 Xcode 4:

xcuserdata

回答by Abizern

Regarding the 'build' directory exclusion -

关于“构建”目录排除 -

If you place your build files in a different directory from your source, as I do, you don't have the folder in the tree to worry about.

如果像我一样将构建文件放在与源不同的目录中,则无需担心树中的文件夹。

This also makes life simpler for sharing your code, preventing bloated backups, and even when you have dependencies to other Xcode projects (while require the builds to be in the same directory as each other)

这也使共享代码的工作变得更简单,防止备份膨胀,甚至当您依赖于其他 Xcode 项目时(同时要求构建彼此位于同一目录中)

You can grab an up-to-date copy from the Github gist https://gist.github.com/708713

您可以从 Github 要点https://gist.github.com/708713获取最新副本

My current .gitignore file is

我当前的 .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

回答by Vladimir Mitrovic

For Xcode 4 I also add:

对于 Xcode 4,我还添加了:

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

回答by program247365

I included these suggestions in a Gist I created on Github: http://gist.github.com/137348

我在 Github 上创建的 Gist 中包含了这些建议:http: //gist.github.com/137348

Feel free to fork it, and make it better.

随意分叉它,让它变得更好。

回答by Eric

The people of GitHub have exhaustive and documented .gitignore files for Xcode projects:

GitHub 的人员为 Xcode 项目提供了详尽的记录 .gitignore 文件:

Swift:https://github.com/github/gitignore/blob/master/Swift.gitignore

斯威夫特:https : //github.com/github/gitignore/blob/master/Swift.gitignore

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

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

回答by onmyway133

You should checkout gitignore.iofor Objective-C and Swift.

对于 Objective-C 和 Swift,您应该查看 gitignore.io

Here is the .gitignorefile I'm using:

这是.gitignore我正在使用的文件:

# Xcode
.DS_Store
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
*.hmap
*.xccheckout
*.xcworkspace
!default.xcworkspace

#CocoaPods
Pods

回答by Wanbok Choi

I'm using both AppCode and XCode. So .idea/should be ignored.

我同时使用 AppCode 和 XCode。所以.idea/应该忽略。

append this to Adam's .gitignore

将此附加到亚当的 .gitignore

####
# AppCode
.idea/

回答by swiftBoy

Adding a .gitignore filefor

添加.gitignore文件以

Mac OS X+ Xcode+ Swift

Mac OS X+ Xcode+ Swift

This is how I have added a .gitignore file into my Swift project:

这就是我将 .gitignore 文件添加到我的 Swift 项目中的方式:

  1. Select you project in Xcode and right click → New Group→ name it "Git"
  2. Select the Git folder and right click → Add new file
  3. Within the iOS tab→ select Otherempty file
  1. 在 Xcode 中选择您的项目并右键单击 →新建组→ 将其命名为“ Git
  2. 选择 Git 文件夹并右键单击 →添加新文件
  3. iOS 选项卡中→ 选择其他空文件

Enter image description here

在此处输入图片说明

  1. Give the file name here ".gitignore"
  1. 在此处输入文件名“ .gitignore

Enter image description here

在此处输入图片说明

  1. Confirm the file name and type
  1. 确认文件名和类型

Enter image description here

在此处输入图片说明

Here is the result structure:

这是结果结构:

Enter image description here

在此处输入图片说明

  1. Open the file and past the below code
  1. 打开文件并粘贴以下代码


# file

#########################################################################
#                                                                       #
#       Title         - .gitignore file                                 #
#       For           - Mac OS X, Xcode 7 and Swift Source projects     #
#       Updated by    - Ramdhan Choudhary                               #
#       Updated on    - 13 - November - 2015                            #
#                                                                       #
#########################################################################

########### Xcode ###########
# Xcode temporary files that should never be committed

## Build generated
build/
DerivedData

# NB: NIB/XIB files still exist even on Storyboard projects, so we want this
*~.nib
*.swp

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata

## Other
*.xccheckout
*.moved-aside
*.xcuserstate
*.xcscmblueprint
*.xcscheme

########### Mac OS X ###########
# Mac OS X temporary files that should never be committed

.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

########## Objective-C/Swift specific ##########
*.hmap
*.ipa

# 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 repository. Instead, use fastlane to re-generate the

fastlane/report.xml
fastlane/screenshots


Well, thanks to Adam. His answer helped me a lot, but still I had to add a few more entries as I wanted a .gitignore file for:

嗯,感谢亚当。他的回答对我帮助很大,但我仍然需要添加更多条目,因为我想要一个 .gitignore 文件:

Mac OS X + Xcode + Swift

Mac OS X + Xcode + Swift

References: thisand this

参考资料:这个这个

回答by tbarbe

Heres a script I made to auto create your .gitignore and .gitattributes files using Xcode... I hacked it together with a few other people's stuff. Have fun!

这是我使用 Xcode 自动创建您的 .gitignore 和 .gitattributes 文件的脚本......我将它与其他一些人的东西一起破解。玩得开心!

Xcode-Git-User-Script

Xcode-Git-用户脚本

No warranties... I suck at most of this - so use at your own peril

没有任何保证......我最不擅长这个 - 所以使用你自己承担风险