如果没有当前分支,`git reset --mixed`在索引方面会做什么? [英] What does `git reset --mixed` do in terms of index if there's no current branch

查看:68
本文介绍了如果没有当前分支,`git reset --mixed`在索引方面会做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,当我不带任何参数和路径运行git reset时,默认为--mixed,git手册将其描述为:

As I understand when I run git reset without any parameters and paths it defaults to --mixed which git manual describes as:

重置索引,但不重置工作树(即,更改后的文件为 保留但未标记为提交),并报告未记录的内容 已更新.

Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated.

我想知道将它重置为什么?我假设它使用git read-tree将某些树读入索引文件,但是在哪里找到那棵树呢?其他一些选项说明,在HEAD文件中找到了树,该树指向提交或分支,因此可以解析树哈希.

I'm wondering what does it reset it to? I assume that it reads some tree into index file using git read-tree, but where does it find that tree? Some other options explain that the tree is found in the HEAD file which points to a commit or branch and hence a tree hash can be resolved.

但是,我已经使用git read-tree aa23将树放入索引中,并且当前我的HEAD文件包含以下内容:

However, I've used git read-tree aa23 to put the tree into index and currently my HEAD file contains the following:

ref: refs/heads/master

但是还没有创建分支. 该树包含两个文件:

But there's no branch created yet. The tree contains two files:

$ git ls-files -s
100644 a1deaae8f9ac984a5bfd0e8eecfbafaf4a90a3d0 0       f1.txt
100644 9b96e21cb748285ebec53daec4afb2bdcb9a360a 0       f2.txt

当我运行git reset时,没有出现任何错误,git status没有报告更改,git ls-files -s没有报告文件.那么索引被重置为什么?

And when I run the git reset I get no errors, git status reports no changes and git ls-files -s reports no files. So what did the index was reset to?

推荐答案

在未出生的分支上运行git reset时,Git明确使用半秘密的空树,作为目标重置:

When running git reset on an unborn branch, Git explicitly uses the semi-secret empty tree as the target of the reset:

unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash);
if (unborn) {
        /* reset on unborn branch: treat as reset to empty tree */
        hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN);
} else if (!pathspec.nr) {

在顶层树为空的情况下,重置任何路径 P 的索引条目的正确(至少从概念上来说)正确的结果是从索引中删除了 P .

With the top level tree being empty, the correct (at least notionally) result for resetting the index entry for any path P is to remove P from the index.

这篇关于如果没有当前分支,`git reset --mixed`在索引方面会做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆