How to revert git uncommitted changes including files and folders

Undo git changes before add and commit

You can list the files that will be reverted without actually making any action, just to check what will happen, with:

git checkout --

Then if you want to undo / revert the changes only in current working directory, use

git checkout -- .

Maybe you wan to know how

git reset --hard

works? It will undo both staged and unstaged changes, whereas ‘git checkout — .’ will undo only unstaged changes.


git reset --hard

will revert changes to modified files. and the following command will remove all untracked files and directories. (`-f` is `force`, `-d` is `remove directories`)

git clean -fd

It is good idea to run

git clean -nd

to preview the changes before running git clean to ensure you don’t have untracked files or directories that you care about that will be removed. -n is dry run which shows output without doing anything yet.

read more here

Web geek, Self-taught full-stack web developer, Learning Python, Laravel, Vuejs, UX/UI design, Nuclear Physicist PhD

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store