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")