0 votes
in Git by
Git discard all changes - How to undo all working dir changes including new files?

Git discard all changes - How to undo all working dir changes including new files?

How to delete all changes from the working directory including new untracked files. I know that git checkout -f does that, but it doesn't delete new untracked files created since the last commit.

Does anybody have an idea how to do that?

1 Answer

0 votes
by

Simple way to do this:

Step 1: Revert modified files using the following command: 

$ git checkout -f

Step 2: Remove untracked files: 

$ git clean -fd

You can refer to Git Tutorial and watch the YouTube video below to get an overwiew of Git.

Warning: 

$ git reset --hard 

This command will remove the staged and working directory modifications. But you have to be very careful while using this command so that you don't end up deleting something you don't want to delete.

So, I think the safest way to deal with this is:

Dry run the command and know what would be deleted before actually deleting anything:

$ git clean -nfd

Once you are sure about the files that you would be deleting perform the following: 

$ git clean -fd

Related questions

0 votes
asked Aug 16, 2020 in Git by RShastri
+1 vote
asked Jul 25, 2019 in Git by Robindeniel
...