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

[BUG] git-stash does not handle branch name with slash correctly

From
Daniel Hahler <git@thequod.de>
Date
Nov 10, 2021, 18:55 UTC
Message-ID
<693b55f9-3c0e-5a31-5a43-d6495d689779@hahler.de>

The default (commit) message when creating a stash strips the beginning of branch names if they contain a slash, e.g. "WIP on 3.2.x: …" instead of "WIP on stable/3.2.x: …"

 From builtin/stash.c (in do_create_stash):
	branch_ref = resolve_ref_unsafe("HEAD", 0, NULL, &flags);
	if (flags & REF_ISSYMREF)
		branch_name = strrchr(branch_ref, '/') + 1;
Whereas git-legacy-stash has this (in create_stash):
	if branch=$(git symbolic-ref -q HEAD)
	then
		branch=${branch#refs/heads/}
	else
		branch='(no branch)'
	fi
	msg=$(printf '%s: %s' "$branch" "$head")

I think it should also strip only "refs/heads/" or use another method that keeps the branch name intact.

(I have noticed this with a script/function that warns me when trying to pop a stash to another branch than where it was stashed from initially, which parses out the (original) branch name from this message.)

[System Info] git version: git version 2.33.1

Next: Jeff King
Message 1 of 5 in “[BUG] git-stash does not handle branch name with slash correctly”
  1. Daniel HahlerNov 10, 2021
  2. Jeff KingNov 10, 2021
  3. stash: strip "refs/heads/" with skip_prefixGlen Choo, Jan 24, 2022
  4. Junio C HamanoJan 25, 2022
  5. Glen ChooFeb 24, 2022

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.