文章目录
误提交大文件以后如何撤销?
我有一个大小超过700MB的文件被错误地提交了, 结果导致git push的操作失败. 提示信息如下:
$ git push
Counting objects: 3, done.
Delta compression using up to 48 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 243.27 MiB | 1.07 MiB/s, done.
Total 3 (delta 1), reused 1 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
remote: error: File: 8e2f0e3a8257bf7483b7b8c56f6a92bd4a9b5427 291.63 MB, exceeds 100.00 MB.
remote: Use command below to see the filename:
remote: git rev-list --objects --all | grep 8e2f0e3a8257bf7483b7b8c56f6a92bd4a9b5427
remote: Please remove the file from history and try again. (https://gitee.com/help/articles/4232)
To https://gitee.com/zhao_zong_yi/pyzahui
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://gitee.com/zhao_zong_yi/pyzahui'
Makefile:2: recipe for target 'update' failed
make: *** [update] Error 1
通过参考此处, 我得到一个非常简洁高效的解决方案. 首先我们根据提示信息执行命令git rev-list --objects --all | grep 8e2f0e3a8257bf7483b7b8c56f6a92bd4a9b5427
, 结果如下:
$ git rev-list --objects --all | grep 8e2f0e3a8257bf7483b7b8c56f6a92bd4a9b5427
8e2f0e3a8257bf7483b7b8c56f6a92bd4a9b5427 output.txt
可见, 导致我们上传失败的文件是output.txt, 因此我们简单地将这个文件删除.
之后, 我们执行命令git status
:
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: output.txt
no changes added to commit (use "git add" and/or "git commit -a")
其中的关键部分是Your branch is ahead of 'origin/master' by 1 commit.
, 即我们有1次提交未成功,