git - 如何从当前提交中删除太大的文件[重复]

问题描述 投票:2回答:2

当我执行以下操作时:

git add *
git commit -m "msg"
git push origin develop

我收到以下错误:

Counting objects: 25, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (24/24), done.
Writing objects: 100% (25/25), 46.43 MiB | 2.49 MiB/s, done.
Total 25 (delta 13), reused 0 (delta 0)
remote: Resolving deltas: 100% (13/13), completed with 11 local objects.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: ffe0c9f32d9cde4cedfc1f4713eb82b9
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File tags is 282.99 MB; this exceeds GitHub's file size limit of 100.00 MB
To https://mygithubrepo
 ! [remote rejected] develop -> develop (pre-receive hook declined)
error: failed to push some refs to 'https://mygithubrepo'

然后我从硬盘上删除了文件'tags',但每次尝试推送时,都会出现同样的错误。该文件从未被推送到我的存储库,因此我只需要将其从当前提交中删除。我尝试过很多东西,但每次都会遇到同样的错误。有帮助吗?

当我做

git ls-files

文件'tags'甚至不会显示在列表中。但它还是试图推动它吗?

git git-commit
2个回答
4
投票

这应该工作:

git rm --cached <big_file>
git commit --amend .

这会从跟踪中删除文件,然后修改先前的提交也不包括此文件。


5
投票

如果您在上次提交中添加了大文件,Derek的答案是正确的。此外,如果您想避免再次添加它,请将其添加到.gitignore文件中。

所以,首先:

git rm --cached <big_file>

然后编辑你的.gitignore文件,添加大文件名。

最后将这些更改添加到舞台上

git add .

此时如果你创建一个新的提交,你将无法推送,因为该文件无论如何都将在你的git文件夹中,所以你需要创建一个fixup commit来修改你添加大文件的提交有:

git commit --fixup <old-commit-hash>

一旦你准备好了,你需要改变,有3种情况:

1 - 你在主人身上承诺一切:

git rebase <old-commit-hash>^ -i --autosquash

2 - 你在一个分支中,你的大文件提交在同一个分支中:

git rebase master -i --autosquash

3 - 您在一个分支中,您的大文件提交位于已经合并的分支中:

git rebase <old-commit-hash>^ -i --autosquash --preserve-merges
© www.soinside.com 2019 - 2024. All rights reserved.