I'm trying to undo all changes since my last commit. I tried git reset --hard
and git reset --hard HEAD
after viewing this post. I responds with head is now at 18c3773… but when I look at my local source all the files are still there. What am I missing?
Git undo all uncommitted or unsaved changes
command linegitgit-resetundo
Related Topic
- Git – Undo working copy modifications of one file in Git
- Git – How to undo the most recent local commits in Git
- Git: How to force “git pull” to overwrite local files
- Git – Move existing, uncommitted work to a new branch in Git
- Git – How to delete a Git branch locally and remotely
- Git – Undo a Git merge that hasn’t been pushed yet
- Git – How to revert a Git repository to a previous commit
- Git – How to rename a local Git branch
Best Answer
This will unstage all files you might have staged with
git add
:This will revert all local uncommitted changes (should be executed in repo root):
You can also revert uncommitted changes only to particular file or directory:
Yet another way to revert all uncommitted changes (longer to type, but works from any subdirectory):
This will remove all local untracked files, so only git tracked files remain:
To sum it up: executing commands below is basically equivalent to fresh
git clone
from original source (but it does not re-download anything, so is much faster):Typical usage for this would be in build scripts, when you must make sure that your tree is absolutely clean - does not have any modifications or locally created object files or build artefacts, and you want to make it work very fast and to not re-clone whole repository every single time.