从Angular 12升级到13后,Github缓存过大

30

我最近将package.json中的所有依赖项升级到最新版本。我从Angular 12.2.0升级到13.0.1,现在github拒绝我的推送,并显示文件大小错误。是否需要在angular.json构建配置文件中定义某些设置来帮助减小这些缓存文件的大小?

remote: warning: File .angular/cache/angular-webpack/72163742903fc8ba00e684045de261c2e3a2fb86/3.pack is 54.01 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File .angular/cache/angular-webpack/72163742903fc8ba00e684045de261c2e3a2fb86/2.pack is 56.42 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: error: Trace: 0b9557fffbe30aac33f6d9858ef97559341c5c1614ace35524fcba85ac99ca76
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File .angular/cache/angular-webpack/72163742903fc8ba00e684045de261c2e3a2fb86/3.pack is 122.06 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File .angular/cache/angular-webpack/72163742903fc8ba00e684045de261c2e3a2fb86/5.pack is 123.92 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File .angular/cache/angular-webpack/f48e9bc724ec0d5ae9a9d2fed858970d0a503f10/0.pack is 154.05 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File .angular/cache/angular-webpack/9327900b3187f0b6351b4801d208e7b58f1af17e/0.pack is 165.50 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File .angular/cache/angular-webpack/663bcd30d50863949acf1c25f02b95cab85c248a/0.pack is 151.56 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File .angular/cache/angular-webpack/663bcd30d50863949acf1c25f02b95cab85c248a/0.pack is 151.55 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.

编辑:

  1. 我使用 Angular cli 创建了这个 repo,并在许多版本的 Angular 中进行维护和更新,直到最近的更新出现了问题。

  2. .gitignore 文件位于应用程序的根目录中,并匹配建议的示例:enter image description here

  3. 当将 /.angular/cache 添加到 gitignore 文件时,我运行了 git rm -rf --cached . && git add . && git commit -m 'fix(gitignore): add angular cache' && git push --set-upstream origin chore/bump-deps 但仍然收到文件大小错误。


9
дҪ зҡ„*.gitignore*ж–Ү件дёӯжҳҜеҗҰеҢ…еҗ«/.angular/cacheпјҹдҪ дёҚеёҢжңӣжҠҠиҝҷдәӣж–Ү件еҠ е…Ҙжәҗд»Јз ҒжҺ§еҲ¶гҖӮ - R. Richards
谢谢,@R.Richards。我应该想到这个的。现在我遇到了理解gitifnore文件的问题。我已经添加了所有以下排列,并运行了git rm -r --cached。但仍然无法使其工作: ./.angular/* .angular/* ./.angular/ .angular/ ./.angular .angular - S. Taylor
最好的方法是在GitHub上找到一个受欢迎的Angular 13演示/存储库,然后复制/比较.gitignore文件——可能只是你错过了某个/* - Drenai
你有其他解决方案吗?我目前正在经历这个问题,我不想失去我的git历史记录。 - Sherwin Ablaña Dapito
@S.Taylor 你的命令里缺少一个点号 - 试一试 git rm -r --cached . - matzar
更新 .gitignore 的步骤如下:
  1. .gitignore 中添加路径(在这种情况下是 .angular/cache
  2. 运行 git rm -r --cached .
  3. 提交更改 就是这样。您的 .gitignore 现在应该正常工作了。
- matzar
2个回答

36

确保你的.gitignore文件位于.angular文件夹的父级文件夹中。
在该.gitignore文件中,只需添加简单的.angular/cache/即可忽略该子文件夹的内容。

检查一下:

git check-ignore -v -- .angular/cache/angular-webpack/72163742903fc8ba00e684045de261c2e3a2fb86/2.pack

您可以在 ganatan/angular-starter/.gitignore(来自Angular 13示例启动器项目)中查看示例,其中 /.angular/cache/ 被用于将规则锚定到存储库的顶层文件夹。

OP S. Taylor评论中 确认:

我很确定那就是我的问题。
我放弃了 dev 分支并更新了我的依赖项,没有使用像 git add . && git commit -m 'fix(gitignore): add angular cache' 这样的复合命令。
确保注意到我暂存了什么。


感谢@VonC的回复。check-ignore命令似乎报告该文件被第35行规则/.angular/cache忽略,但我仍然收到大小警告:$ git check-ignore -v -- .angular/cache/angular-webpack/72163742903fc8ba00e684045de261c2e3a2fb86/2.pack .gitignore:35:/.angular/cache .angular/cache/angular-webpack/72163742903fc8ba00e684045de261c2e3a2fb86/2.pack - S. Taylor
1
@S.Taylor 可能是该文件夹在以前的提交中被跟踪过,而正是这个提交触发了 git push 期间的错误消息。安装 git-sizer,然后使用 git-sizer 找到大型提交,接着使用 git filter-repo 删除该提交,具体步骤请参考 https://stackoverflow.com/a/66452371/6309。如果您使用的是 Windows 操作系统,请参考以下链接获取 git-sizer:https://stackoverflow.com/a/66452371/6309 - VonC
1
感谢@VonC,我非常确定那就是我的问题。如果可能的话,我不想安装git-sizer,所以我放弃了dev分支,并更新了我的依赖项,而没有使用像git add . && git commit -m 'fix(gitignore): add angular cache'这样的复合命令。确保注意到哪些内容已经被暂存。 - S. Taylor
1
@S.Taylor 很好,听起来不错。我已经将您的评论包含在答案中以增加可见性。 - VonC

5

对我来说,问题仍然存在,

我按照以下方式重新配置了git:

  1. 复制配置文件(.git/config
  2. 删除.git文件夹
rm -rf .git
  1. 初始化git
git init 
  1. 将旧配置(p.1)粘贴到新的git配置文件(.git/config)中。

  2. .gitignore文件中添加一行(更多细节:angular-starter/.gitignore):

node_modules
.angular/cache
  1. 添加文件并提交
git add . && git commit -m 'update'

为了避免覆盖之前的提交,请在新分支中推送。
git push -f origin HEAD:<new_branch_name>
  1. 通过覆盖进行push(强制推送会导致旧的提交记录丢失),
git push -f origin HEAD:main
  1. 或者
git push -f origin HEAD:master
  1. 一般来说
git push -f origin HEAD:<branch_name>

这个方法真的有效。即使我忽略了文件并使用了rm cached命令,它显示angular/cache文件夹中的文件已从GIT提交中删除,但它仍然推送整个集合。按照这些步骤,它完美地解决了问题。 - smilu
谢谢老铁。对我来说,只需要创建一个新的仓库就可以了,不需要所有的git历史记录。我甚至都没想到这一点。感谢您先生!感谢上帝您发布了那个。我太累了,这帮助我完成了今天的工作。 - undefined

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