3 回答

TA貢獻1831條經驗 獲得超9個贊
我發現壁球比壁球更有用filter-branch
。我做了以下工作:
在本地刪除大文件。
提交本地刪除。
提交軟重置X號(對我來說是3)
git reset --soft HEAD~3
。然后重新提交所有更改(又稱壁球)
git commit -m "New message for the combined commit"
推送壓縮的提交。
特殊情況(來自用戶@lituo):如果上述方法不起作用,則可能是這種情況。提交1包含大文件,提交1的推送由于大文件錯誤而失敗。提交2刪除了大文件,git rm --cached [file_name]
但提交2的推送仍然失敗。您可以按照相同的步驟,只是使用替代以上HEAD~3
,使用HEAD~2
。

TA貢獻2019條經驗 獲得超9個贊
如果文件是使用最新提交添加的,而您尚未推送到GitHub,則可以刪除文件并修改提交,取自此處:
git rm --cached giant_file
# Stage our giant file for removal, but leave it on disk
git commit --amend -CHEAD
# Amend the previous commit with your change
# Simply making a new commit won't work, as you need
# to remove the file from the unpushed history as well
git push
# Push our rewritten, smaller commit

TA貢獻1806條經驗 獲得超5個贊
您可以使用
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch <file/dir>' HEAD
這將刪除該文件歷史記錄中的所有內容。問題在于該文件存在于歷史記錄中。
該命令更改提交的哈希值,這可能是一個真正的問題,尤其是在共享存儲庫上。在不了解后果的情況下不應執行此操作。
- 3 回答
- 0 關注
- 642 瀏覽
添加回答
舉報