+1 vote
1 view
in Devops and Agile by (15.5k points)
edited by

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?

2 Answers

+1 vote
by (20.6k points)

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

0 votes
by (21.4k points)

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

...