Reset all changes after last commit in git

匿名 (未验证) 提交于 2019-12-03 08:33:39

问题:

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:

First reset the changes

git reset HEAD --hard

then clean out everything untracked. If you want to keep files that are not tracked due to .gitignore, be careful with this command.

git clean -fd


回答2:

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 set clean.requireForce to false:

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

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!