Git: How do you replace your current working directory with a previous commit without branching or git revert?

后端 未结 3 1251
礼貌的吻别
礼貌的吻别 2020-12-18 08:35

Is there an easy way to the following with git?

Basically I want to create a new commit at the top of my commit history that is equivalent to a previous com

3条回答
  •  清酒与你
    2020-12-18 09:09

    Assuming you start from a clean worktree, you could do:

    cd 
    git checkout master
    git checkout 49a732c -- .
    

    When you specify a file (in this case . (the root directory of your repo)) as an argument to git checkout, the checkout will not switch branch (the repo HEAD will remain the same). It will just update the index to make that file match the version of that file from the specified commit. Since you specified the root directory of the repo, all files in the index will be updated to match the specified commit 49a732c

提交回复
热议问题