Skip to content

Help us create more tutorials! Make a donation using the Donate button or become a member using the button below to hide this banner and track your progress.

Discard changes to file – Git


To discard changes to a file, enter the following command in your terminal:

git checkout -- file-name


The above command only works when you’ve modified a file but haven’t staged it yet.

As an example, if you wanted to discard the changes you’ve made to the home page of your website (index.html), you could use the following command:

git checkout -- index.html

Tip: Git will remind you about this command when you use git status and the file hasn’t been staged yet. You should see the following message print out when you use git status:

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)


Write some code in index.html. Then use the following command to discard the changes.

git checkout -- index.html


Undoing Things from the Pro Git book

Back to: Git Course > Git Undoing Things