D:\code\gt>git init
Initialized empty Git repository in D:/code/gt/.git/
D:\code\gt>echo Zero > a
D:\code\gt>git add a
D:\code\gt>git commit -m a
[master (root-commit) 392580e] a
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 a
D:\code\gt>echo One > a
D:\code\gt>git add a
D:\code\gt>git commit -m another
[master 271efba] another
1 files changed, 1 insertions(+), 1 deletions(-)
D:\code\gt>echo Second > a
D:\code\gt>git add a
D:\code\gt>git commit -m "yet another"
[master 8d2041e] yet another
1 files changed, 1 insertions(+), 1 deletions(-)
D:\code\gt>git status
# On branch master
nothing to commit (working directory clean)
D:\code\gt>git checkout 271ef a
D:\code\gt>git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: a
#
如您所见,我以第二次提交时的状态 check out 文件。但是,我不明白为什么它已经添加到索引中。为什么 git 不让我添加?
最佳答案
这一点在git checkout
documentation中并没有完全清楚。 ,所以这是一个好问题。
当你这样做时:
git checkout COMMIT -- PATH
...工作副本和PATH
的索引已使用COMMIT
中的版本进行更新。因此,相对于 HEAD
,运行该命令后暂存的文件确实发生了更改。
关于git - 为什么文件被 check out 到索引中显示的先前变更集已修改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7110869/