Rollback to an old commit using revert multiple times

后端 未结 2 547
半阙折子戏
半阙折子戏 2020-12-24 09:14

I want to rollback to a commit using git revert so I can preserve the history. Is there an easier way to do this then to run git revert for every commit hash I want to reve

2条回答
  •  梦毁少年i
    2020-12-24 10:03

    IMHO the most natural approach is to do (assuming you have a clean working copy):

    git reset --hard $lastnicecommit; git merge -s ours @{1}

    and then git commit --amend to add some description. (On newer versions of git git-merge already lets you specify a description.)

    (@{1} is just referring to the commit your branch pointed to before the reset.)

    This makes a fast-forward change and so documents the history completely. Still the changes introduced in the commits since $lastnicecommit don't introduce any changes.

提交回复
热议问题