How to go back to previous commit without losing last commit in Git?

后端 未结 3 1139
长情又很酷
长情又很酷 2021-02-07 08:01

Here is what I want to do. I want to go back to 2 commits before, bring back the files that changed in that commit as a new commit maybe. But I do not want to lose my last commi

3条回答
  •  佛祖请我去吃肉
    2021-02-07 08:57

    revert makes a new commit that reverts changes made by an older commit. reset --hard changes the HEAD of the current branch to the specified commit. checkout switches the working copy to the specified branch or commit.

    When you reset a branch to an older commit the newer commits are lost if they are not parts of other branches or ancestors of tags (they are still accessible via reflog though).

    It is not clear what do you need to do, the most probable solutions are revert (to fully revert an older commit or series of commits) and rebase -i (to change an older commit or delete it from the history).

提交回复
热议问题