Back

Explore Courses Blog Tutorials Interview Questions
+3 votes
2 views
in DevOps and Agile by (29.3k points)
edited by

How do I discard changes in my working copy that are not in the index?

1 Answer

+4 votes
by (50.2k points)
edited by

You can discard unstaged changes in git using the following commands

For added or modified file that is not staged we use the following

For all unstaged files in the working directory

$git checkout -- .(. For all files)

$ git checkout -- <path to that file>(for a specific file to be discarded)

or you can use

 $git stash 

Then if you need to discard the untracked you can use 

$git clean -i

here -i mean interactive mode then it will open like this 

image

There are options for you and you can select your option, clean will be used to discard the untracked file in git. 

For better understanding about these commands go through the following crash course on git that will help you to understand git well

Browse Categories

...