这是否是“git stash”的有效可视化?操作? [英] Is this a valid visualization of the "git stash" operation?

查看:178
本文介绍了这是否是“git stash”的有效可视化?操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到 git存储操作的良好可视化效果。所以我根据互联网上的一些罕见评论创建了自己的博客。





这个可视化是否正确?

编辑说明:我需要更改 stash @ {0}的颜色因为它不是分支。



存储在我的 .git 目录中的存储位置在哪里?我认为它是一个引用并存储在 refs 中,对吗?




图例:


  • C1,C2 - 提交

  • Idx - 索引

  • WD - 工作目录

  • 虚线和虚线框=>可用于垃圾收集





重新制作的图片 $ b

git stash andafter <$ c $ c> git stash 图本质上是正确的(有两个新的提交,不在任何分支上,由 refs / stash 指向)又名隐藏@ {0} )。这个图中缺少的是索引和工作树本身被重置,就像 git reset --hard 那样 - 事实上,使用 git reset --hard -after git stash



git stash分支之后图表[edit to match new diagram]
很难绘制,但: git stash branch 使用 idx wd 提交来恢复索引状态并工作树,然后从 refs / stash 完全从 中删除它们。这两个提交现在没有任何名称,因此符合垃圾回收的条件( git gc 现在可以在它们到期时立即删除它们,就修剪时间而言,基于您的配置中的 gc.pruneExpire )。新分支名称 test 指向 idx WD idx WD 仍然保证存在。



此时立即做出一个新的提交( git stash branch< name>&&& git commit )将会从恢复的索引,如更新后的图纸。


存储在我的.git目录中的存储位置?


提交本身就是提交,因此像其他任何提交一样存储在 .git / objects / 中(作为宽松或打包的对象)。


我认为这是一个引用并存储在refs中,对吗?


是, refs / stash 是一个参考。 git stash 代码使用(或滥用?)reflog条目为 refs / stash 来管理存储堆栈 ,所以在 refs / stash 本身中的所有哈希ID以及任何 refs / stash reflog条目中的所有哈希ID :它们通过直接指向它来保持 WD >活动,并因此也保持 idx commit(< (code $> c $> c $ c $> c $ c $> c $ c $> code>)的第二个父节点(因为它可以通过 WD commit)。


I can not find a good visualization of the git stash operation. So I created my own based on some rare comments on the internet.

This this visualization correct?

Edit note: I need to change the color of stash@{0} because it's no branch.

Where are stashes stored in my .git directory? I think it's a reference and stored in refs, right?


Legend:

  • C1, C2 - commits
  • Idx - Index
  • WD - working directory
  • dashed line and dashed borders => free for garbage collection

Reworked Image

解决方案

The "before git stash" and "after git stash" graphs are essentially correct (there are two new commits, not on any branch, pointed-to by refs/stash aka stash@{0}). What's missing from this diagram is that the index and work-tree themselves are reset, in the same way git reset --hard does it—in fact, using git reset --hard—after git stash.

The "after git stash branch" graph is [edit to match new diagram] much harder to draw, though: git stash branch uses the idx and wd commits to restore the state of the index and work-tree, and then drops them entirely from refs/stash. Those two commits now have no name at all and are therefore eligible for garbage collection (git gc may now remove them as soon as they expire, in terms of "prune time", based on gc.pruneExpire in your configuration). The new branch name test points to the parent commit to which idx and WD pointed, back when idx and WD were still guaranteed to exist.

Making a new commit immediately at this point (git stash branch <name> && git commit) will make a new commit from the restored index, as in the updated drawing.

Where are stashes stored in my .git directory?

The commits themselves are commits, and hence are stored like any other commit, in .git/objects/ (as loose or packed objects).

I think it's a reference and stored in refs, right?

Yes, refs/stash is a reference. The git stash code uses (or abuses?) the reflog entries for refs/stash to manage the "stash stack", so both the hash ID in refs/stash itself, and all those in any refs/stash reflog entries, matter: they keep the WD commit alive, by pointing directly to it, and hence also keep the idx commit (the ^2 or second parent of WD) alive (since it is reachable through the WD commit).

这篇关于这是否是“git stash”的有效可视化?操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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