What does git stash create?

Asked

Viewed 240 times

5

I always use the git stash, who ends up making a git stash push, and send it to a stack, and then retrieve the changes later using the git stash pop.
So far so good, but I found that there is the command git stash create that should create a save of my work.

It turns out that I tested the command, which returns a value similar to a hash, but does not add anything to the stack, which you can confirm with the git stash list, then my question is, what is the point of git stash create?

1 answer

4


I will explain using as a basis the documentation of the git stash create:

   create
       Create a stash entry (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
       "push" above.

The command create will create a reference of stash and return your id, however, will not put it in the stack of stashes. So if you carry out the command git stash list, he won’t be there.

For example:

$ git stash create
7iFcnyu9Nxtzrmaskq2eZT5MGUK3CgfQpSRj48HV

This -> 7iFcnyu9Nxtzrmaskq2eZT5MGUK3CgfQpSRj48HV is the reference of stash created, as the documentation itself tells us, this is useful when used in scripts, where conditionally (or for any other reason) you can save several references to stashes and store them using the command store when it suits you:

$ git stash store 7iFcnyu9Nxtzrmaskq2eZT5MGUK3CgfQpSRj48HV
$ git stash list
stash@{0}: Created via "git stash store".

The command store will include the reference in the stack of stashes, you can also change the label by adding to the stack:

$ git stash store -m "Meu stash fantastico" 7iFcnyu9Nxtzrmaskq2eZT5MGUK3CgfQpSRj48HV
$ git stash list
stash@{0}: Meu stash fantastico
  • I think I get it, like a script that pulls in the repositories, but first wants to stash and leave a comment. thanks :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.