添加 pod 文件并推送。如何撤消?如何在 Xcode & github 中使用 gitignore?

Added pod files and pushed. How to undo? how to use gitignore in Xcode & github?

这是一个由两部分组成的问题: 1) 我添加了提交并将所有 pod 文件推送到 github。有没有办法可以删除它们而不是将它们再次推送到 github?

2) 我知道 gitignore 可以提供帮助,但我不知道如何使用它。任何人都可以引导我完成使用 gitignore 的过程吗?

所以我想我能做的是,从github获取项目,添加gitignore,然后再次推送。那是对的吗?

github 和 Xcode 的新手,请帮忙。

没错,您需要将 Pods 目录添加到您的 。git忽略

1) 从 github 存储库中删除文件:

git rm -r Pods/

别忘了提交和推送

2) 创建一个git忽略文件:

  1. 打开终端并浏览项目文件夹,其中.git文件夹位于
  2. 类型touch .gitignore
  3. 类型echo "Pods/" > .gitignore

更多信息:here

这就是Cocoapods官方文档所说的。

是否签入 Pods 文件夹由您决定,因为工作流程因项目而异。
它建议您将 Pods 目录置于源代码管理之下,并且不要将其添加到您的 .gitignore。但最终这个决定取决于你:

检查 Pods 目录的好处:

  1. 克隆 repo 后,项目可以立即构建并运行,即使机器上没有安装 CocoaPods。不需要 运行 pod install,也不需要 Internet 连接。
  2. Pod 工件 (code/libraries) 始终可用,即使 Pod 的源(例如 GitHub)出现故障。
  3. 克隆存储库后,保证 Pod 构件与原始安装中的构件相同。

忽略Pods目录的好处:

1.The 源代码控制回购将更小,占用更少 space。 只要所有 Pods 的源代码(例如 GitHub)都可用,CocoaPods 通常能够重新创建相同的安装。 (从技术上讲,当不在 Podfile 中使用提交 SHA 时,无法保证 运行ning pod install 将获取并重新创建相同的工件。在 Podfile 中使用 zip 文件时尤其如此。)

2.There在执行源代码控制操作时不会有任何冲突需要处理,例如合并具有不同Pod版本的分支。

无论您是否签入 Pods 目录,PodfilePodfile.lock 应该总是保持在 版本控制下 .

参考Link:Cocoapods Official Documentation

/Pods.gitignore时的注意事项

如果您在团队中工作,您的队友在他们的机器上安装 pods 时可能会遇到问题,最可能的原因是 Podfile.lock

In summary, Podfile.lock makes sure you don't accidentally upgrade the libraries you pull in while keeping your Podfile concerned only with the new dependencies.

为什么 Podfile.lock 可能会导致问题?

Podfile.lock 锁定第一次安装版本的项目,当您再次执行 pod install 时,这只会在 Podfile 中安装任何新库,不会影响您现有的库通过将它们更新为最新代码。

如果拉取回购不包含 /PodsPodfile.lock 锁定 pods 的版本,因为 .gitignore 并且期望这些版本在您的机器中不存在库已存在。

简单的解决方案

只需删除 Podfile.lock 然后执行 pod install 并且 Podfile.lock 将使用您安装的 pods 版本再次生成。

Note: After removing Podfile.lock and installing the pods, you may interact with different versions of pods than your team.