Используйте для этого git revert --mixed
.
После --intent-to-add
файл будет помещен в индекс, но без его содержимого. Вы хотите удалить его из индекса, не изменяя его в рабочем дереве. Именно это и делает git revert --mixed
.
$ echo "some content.txt" > file.txt
$ git status ; echo "###" ; git status -s
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
file.txt
nothing added to commit but untracked files present (use "git add" to track)
###
?? file.txt
# This will add the file to the index but without its content.
# Hence, for Git all the content has "changed".
$ git add --intent-to-add .
$ git status ; echo "###" ; git status -s
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
new file: file.txt
no changes added to commit (use "git add" and/or "git commit -a")
###
A file.txt
$ git diff # show the content of file.txt
# Resets the index so that file.txt becomes completely new for Git.
$ git reset --mixed
$ git status ; echo "###" ; git status -s
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
file.txt
nothing added to commit but untracked files present (use "git add" to track)
###
?? file.txt
$ git diff # doesn't show the content of file.txt
Обратите внимание, что вы можете использовать -N
для git revert --mixed
, чтобы специально не удалять неотслеживаемые файлы из индекса.