继续删除最新的历史提交 git

时间:2021-03-23 00:51:34

标签: git commit git-commit

我们如何删除 (n) 个最新的历史提交 git

转到新分支后:

$ git checkout -b simple-string 5e020716

然后它需要在检查出来后继续消除最新的提交,确保它没有价值,直到得到值得保留的提交

如何在某种意义上做这样的 git,真的没有别的,因为它只是为了在历史上保留某些提交的记录

1 个答案:

答案 0 :(得分:0)

不断进行探索性更改的标准方法是不断创建分支并进行尝试。

你的例子是一个很好的方法。假设我们知道 5e0207 很好,现在我们正试图决定下一步做什么:

$ git checkout -b tryThisWay 5e020716
# develop, develop, develop...
# oh darn
$ git checkout -b tryAnotherWay 5e020716
# develop, develop, develop...
# oh darn
$ git checkout -b tryAThirdWay 5e020716
# develop, develop, develop...
# aha!

所以现在您可以删除 tryThisWaytryAnotherWay

另一种可能性是继续重置,但风险更大,因为如果您改变主意怎么办?所以你可以去:

$ git checkout -b tryThisWay 5e020716
# develop, develop, develop...
# oh darn
$ git reset --hard 5e020716
# develop, develop, develop...
# oh darn
$ git reset --hard 5e020716
# develop, develop, develop...
# aha!

但是为什么要这样做呢?分支很便宜,硬重置很暴力。

相关问题