![](/img/trans.png)
[英]Why does git checkout <<file>> not work when the same file is in index?
[英]Why does git checkout modify the index without being documented as such?
这是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知识?
在您粘贴问题的手册页中:
<tree-ish>参数可用于指定特定的树状结构(即,提交,标记或树),以在更新工作树之前更新给定路径的索引。
因此,您可以看到,它确实声明将更新索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.