Reset all changes after last commit in git

后端 未结 3 1366
慢半拍i
慢半拍i 2020-12-04 04:45

How can I undo every change made to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files?

3条回答
  •  孤街浪徒
    2020-12-04 05:13

    How can I undo every change made to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files?

    1. You can undo changes to tracked files with:

      git reset HEAD --hard
      
    2. You can remove untracked files with:

      git clean -f
      
    3. You can remove untracked files and directories with:

      git clean -fd
      

      but you can't undo change to untracked files.

    4. You can remove ignored and untracked files and directories

      git clean -fdx
      

      but you can't undo change to ignored files.

    You can also set clean.requireForce to false:

    git config --global --add clean.requireForce false
    

    to avoid using -f (--force) when you use git clean.

提交回复
热议问题