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

Re: [FR] Allow `git stash create` to include untracked changes

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Oct 31, 2019, 13:40 UTC
Message-ID
<20191031134034.GA63909@cat>
In-Reply-To
<nycvar.QRO.7.76.6.1910290806310.46@tvgsbejvaqbjf.bet>
On 10/29, Johannes Schindelin wrote:
> So why does `git stash create -u ...` not work? Because the original
> design of `git stash create` never intended to take any command-line
> arguments other than the stash message. And that design can obviously
> not be fixed without breaking backwards compatibility.

Yup that's exactly right. Not breaking this sort of backwards compatibility is also why we have both 'git stash save' and 'git stash push' nowadays.

We did have a similar conversation back when 'git stash push' was introduced [1]. We almost decided this regression would be okay, but in the end went with calling 'create_stash -m "$*"' internally to circumvent the problem. Now that somebody has an actual usecase we may or may not find this "regression" acceptable. I don't have a strong opinion about it, so this is just to add a little bit of context here.

[1]: https://public-inbox.org/git/20170206155606.xgkmhg656vuc6uki@sigill.intra.peff.net/
Show 35 quoted lines
> What we _could_ do is to add a new command-line option to `git stash
> push` that would make it behave like the `create` subsubcommand: _not_
> update the `refs/stash` ref but instead print the commit hash.
> 
> I am not quite sure how to call this option (`--ephemeral` came to my
> mind, as the created commit is not reachable from anywhere and is hence
> subject to garbage collection).
> 
> A completely different approach would be to allow overriding the ref to
> store the stash in, with an empty value triggering the mode where the
> ref is not updated but the commit hash would be printed instead. I am
> thinking of something like `git stash -r '' push ...`, starting with
> this patch:
> 
> -- snip --
> diff --git a/builtin/stash.c b/builtin/stash.c
> index bb4f6d8d762..43b0a155b1d 100644
> --- a/builtin/stash.c
> +++ b/builtin/stash.c
> @@ -1553,6 +1553,8 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
>  	struct argv_array args = ARGV_ARRAY_INIT;
> 
>  	struct option options[] = {
> +		OPT_STRING('r', "ref", &ref_stash, N_("ref"),
> +			   N_("override `refs/stash`")),
>  		OPT_END()
>  	};
> 
> -- snap --
> 
> The biggest trick will be to make all the code paths safe that assume
> that `ref_stash` refers to a valid ref ;-)
> 
> Ciao,
> Dscho
Previous: Johannes Schindelin
Message 5 of 5 in “[FR] Allow `git stash create` to include untracked changes”
  1. dev@kipras.orgOct 26, 2019
  2. Junio C HamanoOct 28, 2019
  3. Kipras MelnikovasOct 28, 2019
  4. Johannes SchindelinOct 29, 2019
  5. Thomas GummererOct 31, 2019

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.