【问题标题】:Removing one of many commits from master branch keeping rest of commits从主分支中删除许多提交之一,保留其余提交
【发布时间】:2019-05-20 19:39:04
【问题描述】:

我有 20 个提交,我需要删除其中一个提交(提交 #20)。我试过了:

git reset --hard hashID

但它正在将头部移动到那个特定的头部:

HEAD is now at someID

我不想更改头部我只想删除那些更改。

我能做什么?如何删除该特定提交并保留其余提交?

【问题讨论】:

标签: git


【解决方案1】:

如果你不介意重写分支的历史

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,它将还原在当前分支顶端对该修订引入的更改。
猜你喜欢
  • 2015-02-13
  • 2013-09-10
  • 1970-01-01
  • 2023-01-12
  • 2020-10-18
  • 2022-10-15
  • 2014-10-29
  • 1970-01-01
  • 2016-12-29
相关资源
最近更新 更多