Xcode项目的Git忽略文件

958

当我在使用 XcodeGit 结合时,应该包括哪些文件在 .gitignore 中?


19
请访问 https://www.gitignore.io/api/swift,xcode,Cobjective-c,osx。该网页提供了相关的忽略文件,可用于在Git中排除Swift、Xcode、C Objective-C和OSX等方面的文件。 - geekay
2
以上链接产生了一个错误:https://www.gitignore.io/api/swift,xcode,objective-c,osx - the Reverend
21个回答

6

对于 Xcode 5,我可以添加:

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

来源自Berik的回答


5

最好的是,

gitignore.io

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


4
我已经添加了:
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。

你也添加了吗?还是这就是你所做的全部? - hakre
1
是的,我两个都添加了,但xcusersate是主要引发问题的文件。添加它是我能够远程推送代码的唯一方式。否则,我将陷入需要提交才能推送的反馈循环中。所以你提交,然后Xcode 4.5会要求你再次提交,因为先决条件是提交,你永远无法推送。 - user1524957

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

4

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

  • Example: Preview | Edit
    • Programming Languages: Objective-C Swift
    • Build Automation Tool: SwiftPackageManager Carthage
    • IDEs: Xcode
    • Operating Systems: macOS
  • Steps to use in Terminal (Refer to the YouTube Video)
    1. Create Git global config alias (One time only)

      git config --global alias.ignore '!gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi'
      
    2. Enter the project directory

      cd <the project directory>
      
    3. Generate .gitignore file

      git ignore Objective-C,Swift,SwiftPackageManager,Carthage,Xcode,macOS >.gitignore
      
    4. Add and commit .gitignore file

      git add .gitignore
      git commit -m "Add .gitignore file"
      

2

Github的.gitignore文件是我们过去遇到问题的所有文件的集合。现在,如果你从头开始启动一个Xcode项目并让Xcode预配置git仓库,.gitignore中就没有太多需要忽略的内容了:我唯一想要忽略的是xcuserdata/...这有助于不使你的提交变得混乱。 - crosscode
GitHub是我寻找.gitignore文件的第一选择 :) - Ky -

0

我建议使用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

1
对于下一个尝试安装 Joe 的人,请先检查它是否是五年以上的死代码库被重新启用,以免浪费时间。 - Ely Dantas

0
如果有人需要一个标准的.gitignore文件,作为一种简单的方式。
只需在导航到您的项目后,在cmd/终端中运行此行。
npx gitignore Objective-C

我从https://www.youtube.com/watch?v=b0g-FJ5Zbb8(14:50)学习了这个。 - Alwin Jose
注意:根据您的需求,可以将Objective-C替换为Swift、Node等。 - Alwin Jose
-bash: npx: command not found - Mark
请从 https://nodejs.org/en/ 安装 Node。如果仍然无法正常工作,请运行 https://dev59.com/jFUL5IYBdhLWcg3wt6EK#51224061 中提到的命令。 - Alwin Jose

0

这将创建最新的gitignore文件

适用于iOS开发

git ignore swift,ios >.gitignore

针对 macOS 开发

git ignore swift,macos >.gitignore

0

我们发现即使添加了.gitignore和.gitattribte文件,*.pbxproj文件仍然可能会损坏。因此,我们有一个简单的计划。

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

一旦他更新了远程,每个人都将始终拥有一个可工作的副本。如果缺少某些内容,则通知他添加并再次拉取。

这对我们来说没有任何问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接