【发布时间】:2017-07-27 05:23:54
【问题描述】:
git 在 repo 中保留以前的提交。我想知道如何进一步从我的回购历史中删除特定的提交(我有它的 ID)?
【问题讨论】:
-
谁能解释一下?我没听懂
标签: git
git 在 repo 中保留以前的提交。我想知道如何进一步从我的回购历史中删除特定的提交(我有它的 ID)?
【问题讨论】:
标签: git
正如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 时分支仅由单个开发人员使用,这是安全的。
【讨论】: