有时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 be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: a
#
D:\code\gt2>git commit -m a
[master (root-commit) c271e05] a
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a
D:\code\gt2>touch b
D:\code\gt2>git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# b
nothing added to commit but untracked files present (use "git add" to track)
D:\code\gt2>git add b
D:\code\gt2>git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: b
#
rm
取消逻辑不合逻辑add
吗?您认为rm
应该如何表现?
git init
没有任何设置HEAD
可重置。
rm
表示在unix上下文中删除。这与添加到索引并非相反。删除文件的功能不应与更改暂存状态的功能一起重载。如果有实现细节可以方便地进行组合,那么这仅表明git中缺少周到的抽象层,这将使可用性变得清晰。
git rm
既能阶段一个缺失,也unstage的另外)