threads / discuss / 44704

git stash filename - stashing single files.

Subject: git stash filename - stashing single files.

## tl;dr

3 messages between Dec 14, 2016 and Dec 14, 2016.

replies: 2people: 3as markdown or json

Jonas Hartmann· Dec 14, 2016, 13:53 UTC · lore
Hello,
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.

Best
-- 
Dipl.-Soz. Jonas Hartmann
HT Studios · Custom-Tailored Software-Engineering
jh@ht-studios.de
+49 160 9924 4679
http://www.ht-studios.de



begin:vcard
fn:Dipl.-Soz. Jonas Hartmann
n:Hartmann;Jonas
org;quoted-printable:HT Studios =C2=B7 Custom-Tailored Software-Engineering;Founder
adr:;;Mainstr. 93;Pfungstadt;Hessen;64319;Germany
email;internet:jh@ht-studios.de
title:Dipl.-Soz.
tel;work:+49 160 99 24 46 79
x-mozilla-html:FALSE
url:http://www.ht-studios.de
version:2.1
end:vcard
Jeff King· Dec 14, 2016, 14:44 UTC · re: Jonas Hartmann · lore

Re: git stash filename - stashing single files.

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
Paul Smith· Dec 14, 2016, 15:00 UTC · re: Jeff King · lore

Re: git stash filename - stashing single files.

On Wed, 2016-12-14 at 09:44 -0500, Jeff King wrote:
> 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).

I agree that this is a terrible (and inconsistent) interface and I would love to see it changed.

I do use messages on stashes all the time (because I can never remember their context a week later without a hint--just looking at the diff is not enough for me) but I would welcome this change. Definitely the first step would be introducing the "-m" option so people and tools could begin the switch to using it.

← back to recent threads