我在 git 文档中遇到过这个声明:
Checking out a file is similar to using git reset with a file path, except it updates the working directory instead of the stage
链接:https ://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting
部分:“Git 签出文件”
现在假设我有一个仓库和一个test.txt
文件
起初工作目录是干净的:
On branch master
nothing to commit, working tree clean
现在我修改 test.txt
、运行git add
并git status
显示:
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: test.txt
现在我运行git checkout HEAD test.txt
并得到:
Updated 1 path from 58e7043
输出git status
:
On branch master
nothing to commit, working tree clean
根据文档,test.txt
索引中的版本应该保持不变,并且工作目录中的版本应该已经更改回 HEAD 指向的提交中的版本,从而导致工作之间的文件版本不同目录和索引——>在这种情况下不应该git status
输出什么?但git status
没有表明 - 为什么?
通常要从暂存文件到清理工作树,我必须先使用git reset HEAD <filename>
该git checkout HEAD <filename>
文件,但这里似乎两者都做?
我很困惑
编辑 - 有趣的是,如果在暂存文件后test.txt
我运行git checkout test.txt
而不是git checkout HEAD test.txt
得到:
Updated 0 paths from the index
即使这两种形式应该是等价的,而前者HEAD
也默认为(?)
我又糊涂了