2015-06-15 28 views
0

這裏是git checkout treeish -- file做:爲什麼git checkout修改索引而沒有記錄下來呢?

$ 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. 

只有「工作樹」的手冊頁會談,並指出任何關於更新索引。

我不明白不一致。

可執行文件或手冊頁是不正確的? ...或者是否有一些我缺乏的假想的魔法混帳知識?

回答

1

從你在你的問題粘貼手冊頁:

的<樹十歲上下>參數 可用於指定一個特定的樹ISH(即提交,標籤或 樹)更新在更新 工作樹之前給定路徑的索引。

所以你可以看到,它明確指出索引將被更新。

+0

嗯..看起來像是假的重載然後,即,(a)指定什麼文件結帳和(b)告訴git也更新索引。我想要(a)但不是(b)... – Archie

+0

如果您使用'git reset'跟蹤checkout命令,那麼索引中的文件將與repo(在您當前的HEAD)匹配,並且工作目錄仍然會包含您簽出的文件。 –

相關問題