# git stash filename - stashing single files.

3 messages from 2016-12-14 to 2016-12-14. Participants: Jonas Hartmann, Jeff King, Paul Smith.
Thread: https://gitlist.dev/t/44704

## Jonas Hartmann, 2016-12-14 13:53

Subject: git stash filename - stashing single files.
Message-ID: <b528e23b-c763-846e-4040-504a58b690fd@ht-studios.de>
URL: https://gitlist.dev/e/b528e23b-c763-846e-4040-504a58b690fd%40ht-studios.de

```
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, 2016-12-14 14:44

Subject: Re: git stash filename - stashing single files.
Message-ID: <20161214144444.k4v64accedl6xvho@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20161214144444.k4v64accedl6xvho%40sigill.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:

> 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, 2016-12-14 15:00

Subject: Re: git stash filename - stashing single files.
Message-ID: <1481727610.4552.8.camel@mad-scientist.net>
URL: https://gitlist.dev/e/1481727610.4552.8.camel%40mad-scientist.net
In-Reply-To: <20161214144444.k4v64accedl6xvho@sigill.intra.peff.net>

```
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.

```
