gpt4 book ai didi

git - 如何撤消 `` git add --intent-to-add``

转载 作者:行者123 更新时间:2023-12-04 14:13:29 27 4
gpt4 key购买 nike

当我跑 git add --intent-to-add .所有未跟踪的文件将其状态从“未跟踪的文件”( git status -s 显示 ?? )更改为“未暂存以进行提交的更改”( git status -s 现在显示 A )。现在,每当我运行 git diff我也看到了新文件。如何恢复这些状态更改,以便它们再次“未跟踪”?

最佳答案

使用 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
请注意,您可以使用 -Ngit reset --mixed专门 不是 从索引中删除未跟踪的文件。

关于git - 如何撤消 `` git add --intent-to-add``,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62444728/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com