Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
in DevOps and Agile by (19.4k 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 (27.5k 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

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

If you wish, you can also enroll for Git and Git Hub Training.

0 votes
by (29.3k points)


$ 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

Browse Categories