You have files indexed before commit but you want to remove one of them from index so that you don't commit it accidentally. Changes to the file remain intact. For that, we use git reset but it doesn't apply to "untracked" files. For more information, click git reset link.


Check the current status


inanzzz@inanzzz:~/project$ git status
On branch my-feature-branch
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

new file: file_seven.txt
modified: file_two.txt

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: file_five.txt

Untracked files:
(use "git add <file>..." to include in what will be committed)

file_six.txt

Remove file from index


inanzzz@inanzzz:~/project$ git reset HEAD file_two.txt
Unstaged changes after reset:
M file_five.txt
M file_two.txt

Check the current status


As we can see "file_two.php" has been unindexed.


inanzzz@inanzzz:~/project$ git status
On branch my-feature-branch
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

new file: file_seven.txt

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: file_five.txt
modified: file_two.txt

Untracked files:
(use "git add <file>..." to include in what will be committed)

file_six.txt