当我运行git add --intent-to-add .所有未跟踪的文件时,它们的状态从“未跟踪的文件”(git status -s显示??)更改为“未暂存提交的更改”(git status -s现在显示A)。现在,每当我运行时,git diff我也会看到新文件。如何恢复这些状态更改,以便它们再次变得“未跟踪”?
Rol*_*olf 11
用于git reset --mixed此。
之后--intent-to-add,文件将被放置在索引中,但不包含其内容。您希望将其从索引中删除,而不在工作树中更改它。正是如此git reset --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
Run Code Online (Sandbox Code Playgroud)
请注意,您可以使用-Nforgit reset --mixed专门不从索引中删除未跟踪的文件。