我有乙個大小超過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. (
to ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ''
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 ..." to update what will be committed)
(use "git checkout -- ..." 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次提交未成功, 所以我們把我們的提交狀態重置到1次提交之前:
git reset head~1
再次執行git status
命令, 可得如下結果:
$ git status
on branch master
your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
這時候我們便完成了對誤提交的撤銷:
$ git add -a
$ git commit -m "automatic uploading. no comments." || true
on branch master
your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
$ git push
everything up-to-date
git 刪除錯誤提交
起因 不小新把記錄了公司伺服器ip,賬號,密碼的檔案提交到了git 方法 git reset hard git push origin head force 其他 根據 soft mixed hard,會對working tree和index和head進行重置 git reset mixed 此為預...
回滾與刪除錯誤提交
剛才在windows上新開始金融交易演算法的專案,增加了gitignore以後想著跟mac上一樣把暫存區清空再重新儲存。沒想到windows上有些命令和mac上不一樣,一下子把本地所有檔案全刪了。然後自然就是回滾到上乙個,這一步沒問題。之後怎麼刪除錯誤提交?git push f或者git push ...
如何刪除錯誤提交的 git 大檔案
早上小夥伴告訴我,他無法拉下 我沒有在意。在我開始寫 的時候,發現我的 c 盤炸了。因為我的磁碟是蘇菲只有 256g 放了 就沒空間了,於是我查詢到了原來是我的 占用了居然有 2000 m 尋找了很久才發現,原來我小夥伴jake傳了乙個壓縮包上去,乙個1g的包。那麼如何把這個壓縮包徹底從 git 刪...