git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: does a stash *need* any reference to the branch on which it was created?

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Jun 2, 2018, 20:46 UTC
Message-ID
<20180602204650.GE26159@hank.intra.tgummerer.com>
In-Reply-To
<alpine.LFD.2.21.1806021525120.19865@localhost.localdomain>
On 06/02, Robert P. J. Day wrote:
> 
>   i realize that, when you "git stash push", stash graciously saves
> the branch you were on as part of the commit message, but does any
> subsequent stash operation technically *need* that branch name?
    $ git stash list
    stash@{0}: WIP on master: 4e5a9c0166 checkout & worktree: introduce checkout.defaultRemote
                      ^^^^^^

Do you mean this branch name? If so, no, afaik nothing in git stash needs that. It's merely a convenience for the user so they know which branch the stash was based on.

>   it doesn't seem like it -- even "git stash branch" really only needs
> the commit that was the basis of that stash to create the new branch.

Correct, and it knows that by checking the parents of the stash (note that a stash is represented internally as just a commit):

    $ git cat-file commit stash@{0}                                                                                                                                                                          ∞
    tree 9fc2608506404bebdeb0aea54e8c76944ae88a1a
    parent 4e5a9c01669919bcc2452e8e2491ee31dbf647fc
    parent 9e457faad129f832ce0070dcfd1f4cfd3f322df3
    author Thomas Gummerer <t.gummerer@gmail.com> 1527971565 +0100
    committer Thomas Gummerer <t.gummerer@gmail.com> 1527971565 +0100
    WIP on master: 4e5a9c0166 checkout & worktree: introduce checkout.defaultRemote

The first parent here is the commit the stash is based on, so that's what 'git stash branch' is using to base the new branch on.

Show 14 quoted lines
>   so, does any stash operation actually need the originating branch
> name? (i'm guessing no, but i've been wrong before.)
> 
> rday
> 
> -- 
> 
> ========================================================================
> Robert P. J. Day                                 Ottawa, Ontario, CANADA
>                   http://crashcourse.ca/dokuwiki
> 
> Twitter:                                       http://twitter.com/rpjday
> LinkedIn:                               http://ca.linkedin.com/in/rpjday
> ========================================================================
Previous: Robert P. J. DayNext: Junio C Hamano
Message 2 of 4 in “does a stash *need* any reference to the branch on which it was created?”
  1. Robert P. J. DayJun 2, 2018
  2. Thomas GummererJun 2, 2018
  3. Junio C HamanoJun 4, 2018
  4. Robert P. J. DayJun 4, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.