[英]How to remove a previous commit in git from repository?
git
將先前的提交保留在倉庫中。 我想知道如何進一步從回購歷史記錄中刪除特定的提交(我有其ID)?
如https://stackoverflow.com/a/42522493/1507546所述 ,您可以使用git rebase
# 06c8c77^ means the commit just before 06c8c77
git rebase -i 06c8c77^
# Your default editor configured for git will be opened with line similar to the following
在第一部分中,您將看到許多提交,要刪除的提交在底部,您可以為此比較提交哈希。
pick 91c0bd0 track one
....
pick 06c8c77 bla bla bla # the one to remove
要刪除它,如第二部分所述,您需要做的就是從編輯器中刪除該行。
# ....
#
# If you remove a line here THAT COMMIT WILL BE LOST.
之后,您應該保存並退出編輯器。 如果沒有錯誤,則需要更新遠程分支。 例如,如果您的分支名稱為feature/my_branch
,則需要執行以下操作:
git push -f origin feature/my_branch # -f or --force to replace the remote feature/my_branch with the local one
注意:這是安全的,只要使用rebase
時僅由單個開發人員使用分支即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.