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

Re: git stash filename - stashing single files.

From
Jeff King <peff@peff.net>
Date
Dec 14, 2016, 14:44 UTC
Message-ID
<20161214144444.k4v64accedl6xvho@sigill.intra.peff.net>
In-Reply-To
<b528e23b-c763-846e-4040-504a58b690fd@ht-studios.de>
On Wed, Dec 14, 2016 at 02:53:20PM +0100, Jonas Hartmann wrote:
Show 5 quoted lines
> http://stackoverflow.com/questions/3040833/stash-only-one-file-out-of-multiple-files-that-have-changed-with-git#comment32451416_3040833
> 
> Could it be possible to have "git stash [filename][filename]...", to
> stash only single files?
> There seems to be a broad community desire.

I think this would be useful. You can pick and choose with "git stash -p", but I have still often wanted "git stash -p [filename]".

There is one problem, though: any non-option arguments to "git stash save" are interpreted as the stash message. So just:

  git stash save file
would break backwards compatibility. Annoyingly, so would:
  git stash save -- file
which uses the "--" to let you have a message which starts with a dash.

Personally, I think this is a pretty terrible interface. Besides the fact that I have never written a stash message in all my years of using git, it's totally inconsistent with the rest of git (which would use "-m" for the message, and treat arguments as pathspecs).

So it might be worth changing, but we'd probably have to deal with the backwards compatibility fallout, have a deprecation period, etc.

As for "git stash" without "save", there is magic to rewrite:
  git stash [opts]
into
  git stash save [opts]
but it explicitly does not allow non-option arguments. So:
  git stash foo

is an error (and not unreasonably, since "git stash list" creates an ambiguity problem). Perhaps:

  git stash -- foo

could be allowed to treat "foo" as a filename. There wouldn't be any backwards compatibility problems, though it would be weird and inconsistent to be able to specify filenames via the "shortcut" invocation, but not with "git stash save".

-Peff
Previous: Jonas HartmannNext: Paul Smith
Message 2 of 3 in “git stash filename - stashing single files.”
  1. Jonas HartmannDec 14, 2016
  2. Jeff KingDec 14, 2016
  3. Paul SmithDec 14, 2016

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.