【问题标题】:Keep removing latest historical commit git继续删除最新的历史提交 git
【发布时间】:2021-06-19 16:08:21
【问题描述】:

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

去新分店后:

$ git checkout -b simple-string 5e020716

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

从某种意义上说,如何做这样的 git,实际上仅此而已,因为它只是为了保留某些提交的历史记录

【问题讨论】:

    标签: git commit git-commit


    【解决方案1】:

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

    您的示例是继续进行的好方法。假设我们知道 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!
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-23
      • 2015-09-02
      • 2019-11-14
      • 2014-09-29
      • 2011-10-26
      • 2014-11-20
      • 2014-06-27
      • 1970-01-01
      相关资源
      最近更新 更多