Git删除大文件-找不到文件

时间:2019-01-09 09:27:17

标签: git version-control

我正在尝试将我的.git推送到Github。

git push origin master
[...]
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: fc1cc7aed3765ca1e847dee4b7fc831f
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File .terraform/plugins/darwin_amd64/terraform-provider-aws_v1.41.0_x4 is 107.37 MB; this exceeds GitHub's file size limit of 100.00 MB
To [example].git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@[example.git].git'

哪个告诉我

.terraform/plugins/darwin_amd64/terraform-provider-aws_v1.41.0_x4 

太大。

足够公平:

rm -rf .terraform/
git rm -rf .terraform/
git rm -rf --cached .terraform/

哪个给

git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    deleted:    .terraform/plugins/darwin_amd64/lock.json
    deleted:    .terraform/plugins/darwin_amd64/terraform-provider-aws_v1.41.0_x4

所以,似乎还可以。

但是,当再推一次(提交后)时,我遇到了刚开始时完全相同的问题。

除了这次,我的.terraform和本地文件夹中都没有.git

是什么原因导致该问题,我该如何解决?
我怀疑有一些git历史记录需要重写,但是不确定。感谢任何帮助!

编辑 不,其他的答案对我的情况没有帮助。
请参阅下面的答案。

2 个答案:

答案 0 :(得分:1)

这是因为您要推送的提交仍然了解.terraform/,以避免它放弃执行命令的最后一次提交:

git reset --hard HEAD~1

然后从git历史记录中删除.terraform/后创建新提交,并将其推送到Github。

答案 1 :(得分:1)

正如@Croolman指出的那样,以下命令解决了我的问题:
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch .terraform/'