How to revert multiple commits as part of a single commit

前端 未结 3 1170
盖世英雄少女心
盖世英雄少女心 2020-12-14 05:35

This is not a major problem, just something I want to know whether or not is possible.

Let\'s say we have two commits, abcd123 and wxyz789,

相关标签:
3条回答
  • 2020-12-14 06:01
    git revert -n <commits>
    git commit
    

    The first command will do all the reverts without create any commits and stage the final result (the -n option). After that, the commit command creates a single commit.

    0 讨论(0)
  • 2020-12-14 06:12

    In case of complicated reverts, which changes each other, the revert --no-commit might be problematic.

    My simple solution was to do real revert, and the squash:

    git revert <all commits>
    git rebase -i
    

    And then mark all the reverts as squash, except the first one, to create a single commit.

    0 讨论(0)
  • 2020-12-14 06:14

    You can do:

    git revert abcd123
    git revert --no-commit wxyz789
    git commit --amend
    

    ... and then write an appropriate commit message describing the combined effect of reverting both commits.

    0 讨论(0)
提交回复
热议问题