情况:我有一个Git存储库,其中包含已存在于索引中的文件.我对几个文件进行了更改,打开Git并使用"git add"将这些文件添加到我的临时区域.
问题:如何从暂存区域中删除其中一个文件但不将其从索引中删除或撤消对文件本身的更改?
有时,git建议git rm --cached取消暂存文件git reset HEAD file.我什么时候应该使用哪个?
编辑:
D:\code\gt2>git init
Initialized empty Git repository in D:/code/gt2/.git/
D:\code\gt2>touch a
D:\code\gt2>git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# a
nothing added to commit but untracked files present (use "git add" to track)
D:\code\gt2>git add a
D:\code\gt2>git status
# On branch master
#
# Initial commit
#
# Changes to …Run Code Online (Sandbox Code Playgroud) 我在我的本地仓库中对我的一些文件进行了更改,然后我做git add -A了我认为在暂存区域添加了太多文件的情况.如何从暂存区域删除所有文件?
在我这样做之后,我会手动做git add "filename".
当我想取消暂存文件时,我所有的 Git 教程都显示如下内容:
$ git add *
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: README.md -> README
modified: CONTRIBUTING.md
Run Code Online (Sandbox Code Playgroud)
此提示告诉我们git reset用于取消暂存文件。
但是,在我的终端中,我看到:
git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
renamed: cat.js -> catcat.js
renamed: tolendo.gogo -> tolendo.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
readme (copy).md
tolendo (copy).txt
zing (copy).html
Run Code Online (Sandbox Code Playgroud)
我的终端告诉我使用,git …