git - 如何从我当前的提交中删除一个太大的文件
git - how to remove a file that is too big from my current commit
当我执行以下操作时:
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 rm --cached <big_file>
git commit --amend .
这将从跟踪中删除该文件,然后修改之前的提交以不包括该文件。
如果您在上次提交中添加了大文件,那么 Derek 的回答是正确的。
此外,如果您想避免再次添加它,请将其添加到您的 .gitignore 文件中。
所以,首先:
git rm --cached <big_file>
然后编辑您的 .gitignore
文件,添加大文件名。
最后将这些更改添加到舞台
git add .
此时如果你创建一个新的提交,你将无法推送,因为该文件无论如何都会在你的 git 文件夹中,所以你需要创建一个修复提交以便使用以下内容修改添加大文件的提交:
git commit --fixup <old-commit-hash>
准备就绪后,您将需要变基,有 3 种情况:
1 - 你在 master 上提交所有内容:
git rebase <old-commit-hash>^ -i --autosquash
2 - 你在一个分支中并且你的大文件提交在同一个分支中:
git rebase master -i --autosquash
3 - 你在一个分支中,你的大文件提交在一个已经合并的分支中:
git rebase <old-commit-hash>^ -i --autosquash --preserve-merges
当我执行以下操作时:
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 rm --cached <big_file>
git commit --amend .
这将从跟踪中删除该文件,然后修改之前的提交以不包括该文件。
如果您在上次提交中添加了大文件,那么 Derek 的回答是正确的。 此外,如果您想避免再次添加它,请将其添加到您的 .gitignore 文件中。
所以,首先:
git rm --cached <big_file>
然后编辑您的 .gitignore
文件,添加大文件名。
最后将这些更改添加到舞台
git add .
此时如果你创建一个新的提交,你将无法推送,因为该文件无论如何都会在你的 git 文件夹中,所以你需要创建一个修复提交以便使用以下内容修改添加大文件的提交:
git commit --fixup <old-commit-hash>
准备就绪后,您将需要变基,有 3 种情况:
1 - 你在 master 上提交所有内容:
git rebase <old-commit-hash>^ -i --autosquash
2 - 你在一个分支中并且你的大文件提交在同一个分支中:
git rebase master -i --autosquash
3 - 你在一个分支中,你的大文件提交在一个已经合并的分支中:
git rebase <old-commit-hash>^ -i --autosquash --preserve-merges