# Proposal for git stash : add --staged option

4 messages from 2015-04-22 to 2015-06-03. Participants: edgar.hipp@netapsys.fr, Johannes Schindelin.
Thread: https://gitlist.dev/t/39133

## edgar.hipp@netapsys.fr, 2015-04-22 08:30

Subject: Proposal for git stash : add --staged option
Message-ID: <96c00a316c79d9e5a85e199ba7d6f317@netapsys.fr>
URL: https://gitlist.dev/e/96c00a316c79d9e5a85e199ba7d6f317%40netapsys.fr

```
Hello,

There's some feature of git that I have been missing.
When you have a lot of unstaged files, and would like to test what 
happens if you undo some of the changes that you think are unecessary, 
you would rather keep a copy of those changes somewhere.

For example

Changed but not updated:
     M config_test.xml
     M config_real.xml

I have changed both config_test.xml and config_real.xml, but I think the 
changes made in config_test.xml are unnecessary. However, I would still 
like to keep them somewhere in case it breaks something.

In this case for example, I would like to be able to stash only the file 
config_test.xml

Eg:

git add config_test.xml
git stash --staged

So that after this, my git looks like this:

Changed but not updated:
     M config_real.xml

and my stash contains only the changes introduced in config_test.xml

`git stash --keep-index` doesn't give the necessary control, because it 
will still stash everything (and create unnecessary merge complications 
if I change the files and apply the stash)

Best,

Edgar

```

## Johannes Schindelin, 2015-04-22 09:25

Subject: Re: Proposal for git stash : add --staged option
Message-ID: <0082a449b4d1723cb557ac353a04c3af@www.dscho.org>
URL: https://gitlist.dev/e/0082a449b4d1723cb557ac353a04c3af%40www.dscho.org
In-Reply-To: <96c00a316c79d9e5a85e199ba7d6f317@netapsys.fr>

```
Hi Edgar,

On 2015-04-22 10:30, edgar.hipp@netapsys.fr wrote:

> When you have a lot of unstaged files, and would like to test what
> happens if you undo some of the changes that you think are unecessary,
> you would rather keep a copy of those changes somewhere.
> 
> For example
> 
> Changed but not updated:
>     M config_test.xml
>     M config_real.xml
> 
> I have changed both config_test.xml and config_real.xml, but I think
> the changes made in config_test.xml are unnecessary. However, I would
> still like to keep them somewhere in case it breaks something.
> 
> In this case for example, I would like to be able to stash only the
> file config_test.xml
> 
> Eg:
> 
> git add config_test.xml
> git stash --staged
> 
> So that after this, my git looks like this:
> 
> Changed but not updated:
>     M config_real.xml
> 
> and my stash contains only the changes introduced in config_test.xml
> 
> `git stash --keep-index` doesn't give the necessary control, because
> it will still stash everything (and create unnecessary merge
> complications if I change the files and apply the stash)

I often have the same problem. How about doing this:

ˋˋˋsh
git add config_real.xml
git stash -k
git reset
ˋˋˋ

The difference between our approaches is that I keep thinking of the staging area as the place to put changes I want to *keep*, not that I want to forget for a moment.

Having said that, I am sympathetic to your cause, although I would rather have `git stash [--patch] -- [<file>...]` that would be used like `git add -p` except that the selected changes are *not* staged, but stashed instead.

Ciao,
Johannes

```

## edgar.hipp@netapsys.fr, 2015-04-23 06:59

Subject: Re: Proposal for git stash : add --staged option
Message-ID: <5e4970b583a71bb577b0f8b8b9b7828c@netapsys.fr>
URL: https://gitlist.dev/e/5e4970b583a71bb577b0f8b8b9b7828c%40netapsys.fr
In-Reply-To: <0082a449b4d1723cb557ac353a04c3af@www.dscho.org>

```
Hi,


the

> ˋˋˋsh
> git add config_real.xml
> git stash -k
> git reset
> ˋˋˋ

is not very well suited because the -k option to keep the index. 
However, the index will still be put inside the stash.

So what you propose is equivalent to:

ˋˋˋsh
git stash
git stash apply stash@\{0\}
git checkout --config_test.xml
ˋˋˋ

`git stash --patch` can do the job (and I think that's what I'm going to 
use from now), but it's still a bit cumbersome in some situations.

Best,

Edgar

Le 2015-04-22 11:25, Johannes Schindelin a écrit :
> Hi Edgar,
> 
> On 2015-04-22 10:30, edgar.hipp@netapsys.fr wrote:
> 
>> When you have a lot of unstaged files, and would like to test what
>> happens if you undo some of the changes that you think are unecessary,
>> you would rather keep a copy of those changes somewhere.
>> 
>> For example
>> 
>> Changed but not updated:
>>     M config_test.xml
>>     M config_real.xml
>> 
>> I have changed both config_test.xml and config_real.xml, but I think
>> the changes made in config_test.xml are unnecessary. However, I would
>> still like to keep them somewhere in case it breaks something.
>> 
>> In this case for example, I would like to be able to stash only the
>> file config_test.xml
>> 
>> Eg:
>> 
>> git add config_test.xml
>> git stash --staged
>> 
>> So that after this, my git looks like this:
>> 
>> Changed but not updated:
>>     M config_real.xml
>> 
>> and my stash contains only the changes introduced in config_test.xml
>> 
>> `git stash --keep-index` doesn't give the necessary control, because
>> it will still stash everything (and create unnecessary merge
>> complications if I change the files and apply the stash)
> 
> I often have the same problem. How about doing this:
> 
> ˋˋˋsh
> git add config_real.xml
> git stash -k
> git reset
> ˋˋˋ
> 
> The difference between our approaches is that I keep thinking of the
> staging area as the place to put changes I want to *keep*, not that I
> want to forget for a moment.
> 
> Having said that, I am sympathetic to your cause, although I would
> rather have `git stash [--patch] -- [<file>...]` that would be used
> like `git add -p` except that the selected changes are *not* staged,
> but stashed instead.
> 
> Ciao,
> Johannes

```

## edgar.hipp@netapsys.fr, 2015-06-03 13:32

Subject: Re: Proposal for git stash : add --staged option
Message-ID: <3abd6c1640b01ee2c53ef423723480b1@netapsys.fr>
URL: https://gitlist.dev/e/3abd6c1640b01ee2c53ef423723480b1%40netapsys.fr
In-Reply-To: <0082a449b4d1723cb557ac353a04c3af@www.dscho.org>

```
Hi again,

just wanted to tell that I have created a solution by doing a few lines 
of scripting:

git-cstash
ˋˋˋ
#/bin/sh

git commit -m 'temporary, will be stashed soon'
git stash --include-untracked
git reset HEAD^1
git stash
git stash pop stash@{1}
ˋˋˋ

Le 2015-04-22 11:25, Johannes Schindelin a écrit :
> Hi Edgar,
> 
> On 2015-04-22 10:30, edgar.hipp@netapsys.fr wrote:
> 
>> When you have a lot of unstaged files, and would like to test what
>> happens if you undo some of the changes that you think are unecessary,
>> you would rather keep a copy of those changes somewhere.
>> 
>> For example
>> 
>> Changed but not updated:
>>     M config_test.xml
>>     M config_real.xml
>> 
>> I have changed both config_test.xml and config_real.xml, but I think
>> the changes made in config_test.xml are unnecessary. However, I would
>> still like to keep them somewhere in case it breaks something.
>> 
>> In this case for example, I would like to be able to stash only the
>> file config_test.xml
>> 
>> Eg:
>> 
>> git add config_test.xml
>> git stash --staged
>> 
>> So that after this, my git looks like this:
>> 
>> Changed but not updated:
>>     M config_real.xml
>> 
>> and my stash contains only the changes introduced in config_test.xml
>> 
>> `git stash --keep-index` doesn't give the necessary control, because
>> it will still stash everything (and create unnecessary merge
>> complications if I change the files and apply the stash)
> 
> I often have the same problem. How about doing this:
> 
> ˋˋˋsh
> git add config_real.xml
> git stash -k
> git reset
> ˋˋˋ
> 
> The difference between our approaches is that I keep thinking of the
> staging area as the place to put changes I want to *keep*, not that I
> want to forget for a moment.
> 
> Having said that, I am sympathetic to your cause, although I would
> rather have `git stash [--patch] -- [<file>...]` that would be used
> like `git add -p` except that the selected changes are *not* staged,
> but stashed instead.
> 
> Ciao,
> Johannes

```
