ChatGPT解决这个技术问题 Extra ChatGPT

Xcode 项目的 Git 忽略文件

GitXcode 结合使用时,我应该在 .gitignore 中包含哪些文件?

检查https://www.gitignore.io/api/swift,xcode,Cobjective-c,osx
上面的链接产生错误:gitignore.io/api/swift,xcode,objective-c,osx

P
Peter Mortensen

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

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

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

如果您需要自定义,可以使用以下要点: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
#

您不应该忽略 *.lockPodfile.lock(不要介意冗余)。您希望在所有工作区中安装完全相同的版本,而不需要“最新版本”。
我已经删除了 Podfile 部分。我最初没有添加它,所以说其他人添加了它,我不小心将它复制/粘贴到了要点中。对于任何/所有的困惑和误解,我深表歉意。我真的不喜欢 StackOverflow 让任何人编辑你的答案的方式 :(。
现在有一个解释行,逐行解释。这应该使它更清晰,并更容易为您自己的项目进行定制。
@Adam 如我所见,此文件包含 VCS 元数据,因此不应检入 VCS。不,developer.apple.com 上没有提及 xccheckout。但是在官方 github 页面上,这个文件已经包含在 gitignore 文件中。 https://github.com/github/gitignore/blob/master/Objective-C.gitignore
没有官方描述,我们不会忽略任何事情。几乎每次人们这样做时,它迟早都会破坏某人的项目。太危险了 - 不要去那里。所以我拒绝向这个文件添加任何东西,除非我有一个可验证的来源确认可以安全地忽略它!
H
Hagelin

基于 this guide for Mercurial 我的 .gitignore 包括:

.DS_Store
*.swp
*~.nib

build/

*.pbxuser
*.perspective
*.perspectivev3

我还选择包括:

*.mode1v3
*.mode2v3

根据 this Apple mailing list post,它们是“用户特定的项目设置”。

对于 Xcode 4:

xcuserdata

我不是特别喜欢 .pbxuser/.perspective/*.perspectivev3 模式。我更喜欢下面的 .xcodeproj/ !*.xcodeproj/project.pbxproj 它忽略了 *.xcodeproj 中的所有内容,除了 project.pbxproj。
我不会忽略 *.pbxuser、*.perspective 和 *.perspectivev3,因为我喜欢在克隆存储库时保留这些设置。
此外,您可能还想补充一点,您可以像这样制作一个“全局”gitignore 文件: git config --global core.excludesfile ~/.gitignore
我想提醒所有在提交项目后添加 .gitignore 文件的人:您忽略的那些文件仍在被跟踪。您必须使用 git rm --cached <files> 手动将它们从 git 中删除
@SpacyRicochet:自从我写评论以来,评论格式显然发生了变化。因此斜体。我的模式应该看起来像 *.xcodeproj/* !*.xcodeproj/project.pbxproj。当然,现在您确实需要针对工作空间进行调整。
A
Abizern

关于“构建”目录排除 -

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

这也使得共享代码、防止臃肿的备份,甚至当您对其他 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

我确实在项目文件夹之外有 build 文件夹,但是当其他用户构建项目时,默认情况下会在项目中重新创建它 - 所以我发现将它添加到忽略文件是一个更好的解决方案,否则它会被读取到他们的提交。
V
Vladimir Mitrovic

对于 Xcode 4,我还添加:

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

如果您只添加 xcuserdata,那么两者都可以。
出于某种原因,仅添加不带前缀的 xcuserdata 对我不起作用。不过,我认为应该这样做。奇怪的。
P
Peter Mortensen

您应该查看 gitignore.io 以了解 Objective-C 和 Swift。

这是我正在使用的 .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

总是用你的例子。不错的设置!谢谢!
我有一段时间没有使用 gitignore.io - 如果你没有使用,值得检查一下。您可以使用它为您使用的任何 IDE/语言等创建一个 gitignore 文件。它甚至会添加一个 cocoapods 部分。杰出的
E
Eric

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

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

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


这已经发布到上述答案之一。我发现它是:不正确、有问题的支持(超过 100 个未完成的拉取请求!),并且没有记录。它“不正确”的事实是最糟糕的。他们忽略了仅适用于一小部分用途并且没有解释什么或原因!因此:我在上面的回答,纠正了他们的错误并解释了正在做什么以及为什么,所以你可以在一个项目的基础上做出有根据的决定(在一个新项目上,我有时会忘记为什么有些项目在那里 -评论帮助我做出决定:))
@Adam:GitHub 的 .gitignore 现在已经针对 Xcode 6.3.2 和 Swift 进行了更新,所以现在是正确的。它也被记录在案。
是的,但是发布破坏数据的文件并将其保持数月或数年的问题 - 显然不费心对其进行正确测试 - 是你永久牺牲了社区的所有信仰、信任和尊重。为时已晚。
W
Wanbok Choi

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

将此附加到亚当的 .gitignore

####
# AppCode
.idea/

P
Peter Mortensen

添加 .gitignore 文件

Mac OS X + Xcode + 斯威夫特

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

在 Xcode 中选择您的项目并右键单击 → 新建组 → 将其命名为“Git” 选择 Git 文件夹并右键单击 → 在 iOS 选项卡中添加新文件 → 选择其他 → 空文件

https://i.stack.imgur.com/vNPOE.png

在此处给出文件名“.gitignore”

https://i.stack.imgur.com/PXQ4k.png

确认文件名和类型

https://i.stack.imgur.com/lpi25.png

这是结果结构:

https://i.stack.imgur.com/Zof1f.png

打开文件并通过下面的代码

# 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

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

Mac OS X + Xcode + 斯威夫特

参考文献:thisthis


非常有用的答案。我将它作为链接添加到我的 Setting Up Github in Xcode 答案中。
P
Peter Mortensen

我的是一个.bzrignore,但它是相同的想法:)

.DS_Store
*.mode1v3
*.pbxuser
*.perspectivev3
*.tm_build_errors

tm_build_errors 用于当我使用 TextMate 构建我的项目时。它不如 Hagelin 全面,但我认为值得为 tm_build_errors 行发布。


P
Peter Mortensen

对于 Xcode 5,我添加:

####
# Xcode 5 - VCS metadata
#
*.xccheckout

来自Berik's Answer


B
BB9z

大部分答案来自 Xcode 4-5 时代。我推荐一个现代风格的忽略文件。

# 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


完美+1
u
user1524957

我已经添加:

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 并再次推送


你也加了吗?或者这只是你所做的一切?
是的,我都添加了,但 xcusersate 是主要的违规文件。添加这是我可以远程推送代码的唯一方法。否则我被困在一个需要在推送之前提交的反馈循环中。所以你提交,然后 Xcode 4.5 会要求你再次提交,你永远无法推送,因为 pre req 正在提交。
j
joserock85

我使用 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/

P
Peter Mortensen

最好的,

gitignore.io

去选择你的语言,然后它会给你文件。


j
jqgsninimo

gitignore.io:为您的项目创建有用的 .gitignore 文件

示例(macOS Objective-C Swift SwiftPackageManager Carthage)预览编辑

预习

编辑

终端使用步骤(参考 YouTube 视频) 创建 Git 全局配置别名(仅限一次) git config --global alias.ignore '!gi() { curl -L -s https://www.gitignore.io /api/$@ ;}; gi' 进入项目目录 cd <项目目录> 生成.gitignore文件 git ignore macOS,Objective-C,Swift,SwiftPackageManager,Carthage >.gitignore 添加并提交.gitignore文件 git add .gitignore git commit -m "添加.gitignore文件”

创建 Git 全局配置别名(仅限一次) git config --global alias.ignore '!gi() { curl -L -s https://www.gitignore.io/api/$@ ;};吉'

进入项目目录 cd <项目目录>

生成 .gitignore 文件 git ignore macOS,Objective-C,Swift,SwiftPackageManager,Carthage >.gitignore

添加并提交 .gitignore 文件 git add .gitignore git commit -m "添加 .gitignore 文件"


f
funroll

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

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

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


github .gitignore 文件是我们过去遇到问题的所有文件的集合。现在,如果您从头开始一个 Xcode 项目并让 Xcode 预先配置 git 存储库,那么 .gitignore 中没有太多可以忽略的内容:我唯一喜欢忽略的是 xcuserdata/ ...这有助于不弄乱您的提交.
GitHub 是我寻找 gitignores 的第一个地方 :)
B
Basil Abbas

我们确实发现,即使您添加 .gitignore 和 .gitattribte,*.pbxproj 文件也会损坏。所以我们有一个简单的计划。

每个在办公室编码的人都会简单地放弃对该文件所做的更改。在提交中,我们简单地提到了添加到源中的文件。然后推送到服务器。我们的集成管理器会提取并查看提交详细信息并将文件添加到资源中。

一旦他更新了遥控器,每个人都会有一个工作副本。如果缺少某些东西,我们会通知他添加它,然后再次拉动。

这对我们来说已经解决了,没有任何问题。


d
damianesteban

我建议使用 joe 来生成 .gitignore 文件。

对于 iOS 项目,运行以下命令:

$ joe g osx,xcode > .gitignore

它将生成此 .gitignore

.DS_Store
.AppleDouble
.LSOverride

Icon
._*

.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

build/
DerivedData

*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata

*.xccheckout
*.moved-aside
*.xcuserstate

对于下一个尝试安装 Joe 的人,在浪费时间之前检查它是否复活了 5 年以上的死回购
A
Alwin Jose

如果有人需要一个标准的 gitignore 文件作为一种简单的方法。

导航到您的项目后,只需在 cmd/ 终端中运行此行。

npx gitignore Objective-C

我从 youtube.com/watch?v=b0g-FJ5Zbb8 (14:50) 开始研究这个
注意:可以根据您的要求将 Objective-C 替换为 swift、node 等。
-bash: npx: command not found
请从 nodejs.org/en 安装节点 如果仍然无法正常工作,请运行 stackoverflow.com/a/51224061/11844048 中所述的命令
R
Rahul Singha Roy

Xcode 项目的标准 .gitignore 文件的结构 >

.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
!default.xcworkspace
xcuserdata
profile
*.moved-aside
DerivedData
.idea/

这与之前的任何答案有什么不同?不要只是在此处粘贴您的 gitignore 文件,这不会向该主题添加任何内容。
@AshleyMills请先阅读答案,然后添加评论....答案是针对标准结构/必需的....