Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

You have a lot of files to be indexed/staged with git add and then committed afterwards however, you want to avoid a file by also reverting the changes to it. To do that git checkout -- is used. For more information, click git checkout link.


Check the current status


inanzzz@inanzzz:~/project$ git status
On branch develop
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)

modified: index.html.twig
modified: hello.html.twig

no changes added to commit (use "git add" and/or "git commit -a")

Remove file from working tree


Let's get rid of "index.html.twig" so that we don't stage it accidentally.


inanzzz@inanzzz:~/project$ git checkout -- index.html.twig
inanzzz@inanzzz:~/project$ git status
On branch develop
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)

modified: hello.html.twig

no changes added to commit (use "git add" and/or "git commit -a")