Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to revert uncommitted changes including files and folders?

Is there a git command to revert all uncommitted changes in a working tree and index and to also remove newly created files and folders?

like image 458
MEM Avatar asked Apr 27 '11 16:04

MEM


People also ask

Can I get back uncommitted changes?

The "restore" command helps to unstage or even discard uncommitted local changes. On the one hand, the command can be used to undo the effects of git add and unstage changes you have previously added to the Staging Area.

How do you dispose of uncommitted changes?

Use git reset to Remove Uncommitted Changes in Git Another way to remove uncommitted changes using git reset is with option --hard and params HEAD . The --hard option specifies Git to throw ALL changes between the current state and the commit in the last argument.


2 Answers

You can run these two commands:

# Revert changes to modified files. git reset --hard  # Remove all untracked files and directories. # '-f' is force, '-d' is remove directories. git clean -fd 
like image 75
htanata Avatar answered Oct 03 '22 08:10

htanata


If you want to revert the changes only in current working directory, use

git checkout -- . 

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

git checkout -- 
like image 41
Ramashish Baranwal Avatar answered Oct 03 '22 08:10

Ramashish Baranwal