DEV Community

Aleksandr Ippatev
Aleksandr Ippatev

Posted on

How do revert all local changes in Git?

git-logo

If you want to revert changes made to your working copy, do this:



git checkout .


Enter fullscreen mode Exit fullscreen mode

If you want to revert changes made to the index (i.e., that you have added), do this. Warning this will reset all of your unpushed commits to master!:



git reset


Enter fullscreen mode Exit fullscreen mode

If you want to revert a change that you have committed, do this:



git revert <commit 1> <commit 2>


Enter fullscreen mode Exit fullscreen mode

If you want to remove untracked files (e.g., new files, generated files):



git clean -f


Enter fullscreen mode Exit fullscreen mode

Or untracked directories (e.g., new or automatically generated directories):



git clean -fd


Enter fullscreen mode Exit fullscreen mode

Top comments (0)