search

Home  >  Q&A  >  body text

GIT如何删除一个中间的错误commit并保留后面正确的commit

如题,中间有一个错误的commit,然后后面又有一堆正确的,现在想删除这个错误,并保留正确的,如何操作?

phpcn_u1582phpcn_u15822763 days ago741

reply all(5)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-02 09:34:27

    The normal approach is to rebase and process subsequent commits manually (resubmit all useful commits, ignore useless commits, and merge redundant commits). The risks and difficulties are relatively high. (Repair the situation, save the sheep and kill the wolf)

    The lazy way is to go back to before the wrong commit, and then resubmit with a new branch. This is safe, but the workload will be relatively large, and it is easy to make mistakes in the middle. (Repair the sheep’s fold, mend the sheepfold and save the sheep)

    It’s even more lazy to commit a new submission later to correct the previous error. (Repair the lost sheep, mend the sheepfold and buy a new sheep)

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-02 09:34:27

    git revert wrong_commit

    reply
    0
  • 黄舟

    黄舟2017-05-02 09:34:27

    git rebase -i returns to a previous version containing the wrong submission. There is an option to abandon a certain submission. Please refer to Baidu for specific usage

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-02 09:34:27

    I don’t know if you are asking about commit --amend...

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-02 09:34:27

    It doesn’t seem to work, unless you RESET back to the previous submission, then delete the subsequent submission log, and then resubmit what you need. I checked before.

    reply
    0
  • Cancelreply