存储后出现的那些'WIP'和'index'提交是什么? [英] What are those 'WIP' and 'index' commits that appear after stashing?
问题描述
当我在本地开发分支上运行 git lg
时,最新的提交如下所示:
* 7d21213 - (1小时前)更新业务规则 - developer1(HEAD,origin / develop,origin / HEAD,develop)
但是,如果我通过运行 git stash
来存储本地更改,然后运行 git lg
,我得到以下内容:
* at12334 - (13秒前)WIP on develop:7d21213更新业务规则 - developer1(refs / stash)
| \
| * ef9a11b - (14秒前)index on develop:7d21213更新业务规则 - developer1
| /
* 7d21213 - (1小时前)更新业务规则 - developer1(HEAD,origin / develop,origin / HEAD,develop)
这是什么意思?看来在存储之后会创建两个新的提交(标记为 index
和 WIP
)。是这种情况,如果是这样的话,这种提交背后的逻辑是什么?
注意
git lg
是已经在测试环境中定义的别名:
git log --graph --abbrev-commit --decorate --date =相对 - 格式=格式:'%C(粗体蓝色)%h%C(复位) - %C(粗体绿色)(%ar)%C(复位)%C(白色)%s%C %C(dim white)'--all
git lg
?什么 git lg
?
请注意, lg
是不是原生的Git动词。诚然,许多人使用通常对应于
的别名 lg
git log --all --oneline --graph --decorate
这个定义似乎是一个你正在使用,在这里。但是,别名是本地的;你的配置中的 git lg
意味着什么可能与Bob和Alice的配置中的含义不同。
因此,您应该始终在您的问题中包含相关别名的定义,因此我们(Stack Overflow用户)可以与您位于同一页面上,并确切知道在您运行时发生了什么。
git<别名>
( git lg
,here)。
神秘物品是什么
这个在讨论部分解释 git-stash
手册页:
存储表示为一个提交,其记录的是
工作目录的状态,其第一个父项是提交在HEAD时,
存款被创建。第二个父节点的树记录了
的索引状态,并将其作为HEAD
提交的子节点。祖先图看起来像这样:.---- W
/ /
--- --H ---- I
其中
H
是HEAD
提交,I
是一个用于记录索引状态的提交,W
是一个提交,用于记录
工作树的状态。
你的情况,
- 对象的短SHA是
ef9a11b
对应于您的索引(上图中的I
),
- 其短SHA <
at 12334 对应于您工作目录的状态(上图中的 W
)。
- 其短SHA <
这两个对象( W
和 I
)通常不会在 git log
,但是如果您使用 - all
标志,它们会执行。
When I run git lg
on my local development branch, the latest commit is shown as below:
* 7d21213 - (1 hours ago) update business rules - developer1 (HEAD, origin/develop, origin/HEAD, develop)
However, if I stash local changes by running git stash
and then run git lg
, I get the following:
* at12334 - (13 seconds ago) WIP on develop: 7d21213 update business rules - developer1 (refs/stash)
|\
| * ef9a11b - (14 seconds ago) index on develop: 7d21213 update business rules - developer1
|/
* 7d21213 - (1 hours ago) update business rules - developer1 (HEAD, origin/develop, origin/HEAD, develop)
What does this mean? It seems that two new commits (labelled index
and WIP
) are created after stashing. Is that the case, and, if so, what is the logic behind such commits?
Note
git lg
is an alias already defined in the test environment as
git log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)' --all
git lg
? What git lg
?
Be aware that lg
is not a native Git verb. True, many people use an alias called lg
that usually corresponds to
git log --all --oneline --graph --decorate
This definition seems to be the one you're using, here. However, aliases are local; what git lg
means in your config may be different to what it means in Bob and Alice's configs.
Therefore, you should always include the definition of a relevant alias in your question, so we (Stack Overflow users) can be on the same page as you, and know exactly what happens when you run
git <alias>
(git lg
, here).
What the mysterious objects are
This is explained in the Discussion section of the git-stash
man page:
A stash is represented as a commit whose tree records the state of the working directory, and its first parent is the commit at HEAD when the stash was created. The tree of the second parent records the state of the index when the stash is made, and it is made a child of the HEAD commit. The ancestry graph looks like this:
.----W / / -----H----I
where
H
is theHEAD
commit,I
is a commit that records the state of the index, andW
is a commit that records the state of the working tree.
In your case,
- the object whose short SHA is
ef9a11b
corresponds to the state of your index (I
on the graph above), - the object whose short SHA is
at12334
corresponds to the state of your working directory (W
on the graph above).
Those two objects (W
and I
) don't normally get listed in the output of git log
, but they do if you use the --all
flag.
这篇关于存储后出现的那些'WIP'和'index'提交是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!