git stash创建和git stash存储的目的是什么? [英] What is the purpose of git stash create and git stash store?

查看:83
本文介绍了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

这篇关于git stash创建和git stash存储的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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