How do I reset the working tree without moving HEAD?

后端 未结 3 1539
青春惊慌失措
青春惊慌失措 2021-01-04 13:19

Given a git branch with some commits on it (C is the most recent commit):

A -> B -> C

How do I reset my workspace so that all the fil

3条回答
  •  渐次进展
    2021-01-04 14:01

    git checkout [-p|--patch] [] [--] ...

    git checkout with or --patch is used to restore modified or deleted paths to their original contents from the index or replace paths with the contents from a named (most often a commit-ish).

    So you need to run this at root of your repository (works fine for any sub-tree or file(s) too):

    git checkout HEAD~ -- .
    

    This will result in git applying changes necessary to revert files to HEAD~ state, the changes will be in the index.

提交回复
热议问题