Git Stashes 存储在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40653560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:26:39  来源:igfitidea点击:

Where are Git Stashes stored?

gitgit-stash

提问by Typhoon101

I have been using PhpStorm and recently stashed a load of my changes. At some point after that, my PC profile became corrupt and had to be rebuilt.

我一直在使用 PhpStorm,最近保存了我的大量更改。在那之后的某个时候,我的 PC 配置文件损坏了,必须重建。

Now that I have a new PC profile, PhpStorm is not showing my stashed changes.

现在我有了一个新的 PC 配置文件,PhpStorm 没有显示我隐藏的更改。

Is there any way I can get them back?

有什么办法可以让他们回来吗?

回答by Paul

From the docs, the latest one is stored in ./.git/refs/stashwhile older ones are in the reflogof that ref.

从文档中,最新的存储在其中,./.git/refs/stash而旧的存储在reflog其中ref

As an aside, I've found it's a bad practice to maintain a regular use of git stash. Generally, prefer many small commits on a feature branch. This way you rarely have to stash and when you do it's very little stored as such. I generally stash only when I need to touch something away for a few minutes, and then apply when I'm done looking at something.

顺便说一句,我发现经常使用 git stash 是一种不好的做法。通常,更喜欢在功能分支上进行许多小的提交。这样你很少需要藏起来,当你这样做时,它很少被储存。我通常只在我需要触摸某物几分钟时才将其藏起来,然后在我看完某物时应用。

https://git-scm.com/docs/git-stash

https://git-scm.com/docs/git-stash

回答by Steven J Owens

The actual data stashed by "git stash" (i.e. the current version of the working tree and the contents of .git/index) is stored as two commit trees.

“git stash”存储的实际数据(即工作树的当前版本和 .git/index 的内容)存储为两个提交树。

One commit tree contains a snapshot of the current state of the working tree. There are some tricky bits here, see below.

一个提交树包含工作树当前状态的快照。这里有一些棘手的地方,见下文。

The other commit tree, I've been told, is used to store a snapshot of the contents of .git/index at the time of the stash. I haven't looked into this deeply enough (yet) to understand how the one is translated into the other.

有人告诉我,另一个提交树用于存储 .git/index 在 stash 时的内容快照。我还没有对此进行足够深入的研究(还)以了解如何将一个翻译成另一个。

.git/refs/stash contains the hash value for the commit tree that the stash created.

.git/refs/stash 包含存储创建的提交树的哈希值。

.git/logs/refs/stash contains a reflog-like chunk of metadata about the stashes before the one in .git/refs/stash.

.git/logs/refs/stash 在 .git/refs/stash 之前包含了一个类似于 reflog 的元数据块,这些元数据是关于 stash 的。

.git/index holds a list of entries, one for each of the files in the working tree. Those entries contain the full path and filename and also cached metadata about the file, both filesystem metadata and git-related metadata.

.git/index 包含一个条目列表,工作树中的每个文件对应一个条目。这些条目包含完整路径和文件名,还包含有关文件的缓存元数据,包括文件系统元数据和与 git 相关的元数据。

"git add" both adds a copy of a file to the object store, and sets the staging flag for that file in .git/index.

“git add”既向对象存储添加文件副本,并在 .git/index 中设置该文件的暂存标志。

For "git stash" to create a commit tree, files that have been changed (edited) but not yet staged with "git add" have to be added to the object store. "git stash" does this by building a temporary index file.

对于“git stash”创建提交树,必须将已更改(编辑)但尚未使用“git add”暂存的文件添加到对象存储中。“git stash”通过构建一个临时索引文件来做到这一点。

回答by Shravan40

All are stored in .git/refs/stash. git stashsaves stashes indefinitely, and all of them are listed by git stash list.

全部存储在.git/refs/stash. git stash无限期地保存 stash,并且所有这些都由 列出git stash list

Please note that dropping or clearing the stash will remove it from the stash list, but you might still have unpruned nodes with the right data lying around.

请注意,删除或清除 stash 会将其从 stash 列表中删除,但您可能仍然有未修剪的节点,其中包含正确的数据。