3 回答

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

TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊
如果文件是使用最新提交添加的,而您尚未推送到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貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊
您可以使用
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch <file/dir>' HEAD
這將刪除該文件歷史記錄中的所有內(nèi)容。問(wèn)題在于該文件存在于歷史記錄中。
該命令更改提交的哈希值,這可能是一個(gè)真正的問(wèn)題,尤其是在共享存儲(chǔ)庫(kù)上。在不了解后果的情況下不應(yīng)執(zhí)行此操作。
- 3 回答
- 0 關(guān)注
- 652 瀏覽
添加回答
舉報(bào)