以下是git checkout treeish -- file
的作用:
$ git init foo
$ cd foo/
$ echo aaaa > file.txt
$ git add file.txt
$ git commit -m 'commit aaaa'
$ git checkout -b bbbb
$ echo bbbb > file.txt
$ git add file.txt
$ git commit -m 'commit bbbb'
$ git checkout master
$ git checkout bbbb -- file.txt
$ cat file.txt
bbbb
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: file.txt
请注意,file.txt
不仅已修改为包含bbbb
,,而且此更改也已添加到索引。
然而,该手册页指出:
DESCRIPTION
Updates files in the working tree to match the version in the index
or the specified tree. If no paths are given, git checkout will
also update HEAD to set the specified branch as the current branch.
...
git checkout [-p|--patch] [<tree-ish>] [--] <pathspec>...
When <paths> or --patch are given, git checkout does not switch
branches. It updates the named paths in the working tree from
the index file or from a named <tree-ish> (most often a commit).
In this case, the -b and --track options are meaningless and
giving either of them results in an error. The <tree-ish> argument
can be used to specify a specific tree-ish (i.e. commit, tag or
tree) to update the index for the given paths before updating
the working tree.
该手册页仅讨论“工作树”,并且没有说明更新索引。
我不明白这种不一致。
可执行文件或手册页是否不正确? ...或者我缺少一些假设的魔法git知识吗?
答案 0 :(得分:1)
从您在问题中粘贴的手册页:
&lt; tree-ish&gt;争论 可用于指定特定的树(即提交,标记或 tree)在更新之前更新给定路径的索引 工作树。
所以你可以看到,它确实明确表示将更新索引。