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



我想把我的NextJS项目推到GitHub,但我总是得到一个错误,说我的。next/cache文件夹超过GitHub的文件大小限制。

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

这是我的。gitignore文件
node_modules
next
.env

然后我按照下面的步骤:

  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

我写错了什么在我的。gitignore文件或有其他问题?

谢谢你的帮助!

唯一对我有效的方法是:

git rm --cached .next/ -r

然后检查git状态

git status

检查前方距离

On branch master
Your branch is ahead of 'origin/master' by 8 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean

然后运行下面的命令,加上你的进度

git reset HEAD~8

:

git add .
git commit -m "bug fix"
git push -u origin main 

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

为了解决这个问题,你需要从存储库历史中完全删除它们。https://docs.github.com/en/github/managing-large-files/working-with-large-files/removing-files-from-a-repositorys-history提供了一些指导。

next和。next是不同的文件夹。

最新更新