git - 为什么文件被 check out 到索引中显示的先前变更集已修改?

标签 git

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/

相关文章:

Git描述给不同的标签

Git 配置 user.name 不起作用

git - 当它说 : An experimental "version 4" format of the index file 时,它在 msysgit 1.7.11 的变更日志中意味着什么

git - 如何解压打包引用?

git - 使用 Git Flow 时如何保持分支同步

git - 计算特定用户在 Github 中所有项目中编写的总行数

git - 从远程仓库中提取 gitignored、未跟踪的文件时会发生什么?

git - 从 git 历史记录中删除文件 - 错误的修订错误

git - 2次提交之间的所有提交列表

ios - Git 上的 Push 错误,然后是 Pull 和 Workspace 上的错误