Как отменить `` git add --intent-to-add`` - PullRequest
0 голосов
/ 18 июня 2020

Когда я запускаю git add --intent-to-add ., все неотслеживаемые файлы меняют свое состояние с «Не отслеживаемые файлы» (git status -s показывает ??) на «Изменения, не предназначенные для фиксации» (git status -s теперь показывает A). Теперь, когда я запускаю git diff, я тоже вижу новые файлы. Как мне отменить эти изменения состояния, чтобы они снова стали «неотслеживаемыми»?

1 Ответ

0 голосов
/ 18 июня 2020

Используйте для этого 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, чтобы специально не удалять неотслеживаемые файлы из индекса.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...