git stash创建和git stash存储的目的是什么?

git stash创建和git stash存储的目的是什么?

问题描述:

git-scm 的文档中,有两个提到的git stash命令与脚本相关,但不通用:

From the documentation at git-scm, there are two git stash commands that mention relevance to scripting, but not general use:

创建

创建一个存储区(它是一个常规的提交对象)并返回其对象名称,而不将其存储在ref名称空间中的任何位置.旨在对脚本有用.它可能不是您要使用的命令;请参阅上方的保存".

Create a stash (which is a regular commit object) and return its object name, without storing it anywhere in the ref namespace. This is intended to be useful for scripts. It is probably not the command you want to use; see "save" above.

商店

将通过git stash create(这是一个悬而未决的合并提交)创建的给定stash存储在stash ref中,以更新stash reflog.旨在对脚本有用.它可能不是您要使用的命令;请参阅上方的保存".

Store a given stash created via git stash create (which is a dangling merge commit) in the stash ref, updating the stash reflog. This is intended to be useful for scripts. It is probably not the command you want to use; see "save" above.

假设我们正在考虑自动化脚本的上下文,与通常的git stash save和朋友相比,git stash creategit stash store给我带来什么好处?

Supposing that we are considering the context of automated scripts, what advantages do git stash create and git stash store give me over the usual git stash save and friends?

在编写需要隐藏为实现细节的脚本并且不想打扰用户的隐藏引用时,可以使用git stash create.

You can use git stash create when you're writing scripts that need to stash as an implementation detail and you don't want to disturb the user's stash reflog.

根据接下来发生的情况,您可能(例如在发生错误的情况下)决定是否确实要打扰存储刷新,此时可以使用git stash store.

Depending on what happens next, you might (in the case of error, say) decide you do want to disturb the stash reflog after all, at which point you can use git stash store.

很显然,可以按create然后按store的方式实现常规存储,但是我也可以想象它被用在假设的update-branch命令中,该命令执行以下操作:

Obviously a regular stash can be implemented in terms of create then store, but I can also imagine it being used in a hypothetical update-branch command that does something like this:

git stash create
git fetch
git rebase
git stash apply