如何忽略 git 中的目录

How to ignore a directory in git

所以最新版本的GoogleMaps框架是123MB,这导致了GitHub的100MB限制的各种问题。我试过 Large File Storage,但这不起作用。所以现在我试图忽略我的 Pods 目录。我将 .gitignore 文件编辑为如下所示:

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

# 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/

但是当我尝试推送时,我仍然从 GoogleMaps Pod 收到相同的文件太大错误。我错过了什么?

编辑:对于那些不相信的人来说,这是确切的错误:

File Pods/GoogleMaps/Frameworks/GoogleMaps.framework/Versions/A/GoogleMaps is 123.00 MB; this exceeds GitHub's file size limit of 100.00 MB

这是一个 Git集线器问题。

您需要确保该文件根本不在您的存储库中。这意味着从所有提交中删除该文件。将文件添加到 .gitignore 不会从 Git 中删除文件(如果您已经添加了它们),并且从最新提交中删除文件不会从存储库中删除该文件,因为该文件仍然存在于存储库中历史记录(换句话说,git rm 没有帮助)。

要完全删除文件,请编辑历史记录。参见:Completely remove file from all Git repository commit history

.gitignore 我觉得不错。我可以想到以下原因,为什么你仍然达到 100MB 限制:

  • 您已经添加了 Pods 目录,但目前尚未提交。在这种情况下 git rm --cached <filename> 是你的朋友
  • 您在之前的提交中提交了 Pods 目录。由于 git 上传远程版本和本地版本之间的所有中间更改,因此 Pods 目录将被上传,即使它在最近的提交中再次被删除。在这种情况下,从历史记录中删除 Pods 目录的唯一方法是 git rebase.

试试这个

git update-index --assume-unchanged '/pods' 然后做 git status 只是为了确定我们要提交什么。现在这次它不应该包含 "pods" 目录。

希望这有帮助吗?