BlackVegetable BlackVegetable - 3 months ago 11
Git Question

What is the purpose of git stash create and git stash store?

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


create

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.

store

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.


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?

Answer

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.

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.

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
Comments