【发布时间】:2019-05-20 19:39:04
【问题描述】:
我有 20 个提交,我需要删除其中一个提交(提交 #20)。我试过了:
git reset --hard hashID
但它正在将头部移动到那个特定的头部:
HEAD is now at someID
我不想更改头部我只想删除那些更改。
我能做什么?如何删除该特定提交并保留其余提交?
【问题讨论】:
标签: git
我有 20 个提交,我需要删除其中一个提交(提交 #20)。我试过了:
git reset --hard hashID
但它正在将头部移动到那个特定的头部:
HEAD is now at someID
我不想更改头部我只想删除那些更改。
我能做什么?如何删除该特定提交并保留其余提交?
【问题讨论】:
标签: git
如果你不介意重写分支的历史:
git checkout hashID~1 # stand on the previous revision
git cherry-pick hashID..the-branch # replay all revisions after the one I want to remove
# if you like the results
git branch -f the-branch
【讨论】:
git revert hashID,它将还原在当前分支顶端对该修订引入的更改。