如何将大型 NextJS 项目推送到 GitHub

Ben*_*nni 6 git github next.js

我想将我的 NextJS 项目推送到 GitHub,但总是收到一条错误消息,指出我的 .next/cache 文件夹超出了 GitHub 的文件大小限制。

我尝试通过将下一个文件夹添加到 .gitignore 文件来解决此问题。

这是我的 .gitignore 文件

node_modules
next
.env
Run Code Online (Sandbox Code Playgroud)

然后我按照以下步骤操作:

  1. .gitignore在文件中进行更改
  2. 运行git rm -r --cached .命令。
  3. 运行git add .命令
  4. git commit -m "Commit message"或者只是git commit或者继续工作。
  5. git push

但仍然没有成功。

我得到的错误

remote: error: File .next/cache/webpack/client-development/32.pack is 122.93 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File .next/cache/webpack/client-development/71.pack is 126.09 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File .next/cache/webpack/client-development/9.pack is 155.84 MB; this exceeds GitHub's file size limit of 100.00 MB
Run Code Online (Sandbox Code Playgroud)

我在 .gitignore 文件中写了一些错误的内容还是还有其他问题?

谢谢你帮忙!

Mat*_*aly 3

我强烈怀疑问题在于这些文件可能已被删除,但从您上次推送到现在,它们仍然存在于存储库的历史记录中。已提交并在稍后提交中删除的文件仍存在于存储库历史记录中。

因此,为了解决该问题,您需要将它们从存储库历史记录中完全删除。https://docs.github.com/en/github/managing-large-files/working-with-large-files/removing-files-from-a-repositorys-history提供了一些关于执行此操作的指导。