git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* stash push/pop unstages files?
@ 2021-09-05 17:09 Yuri
  2021-09-05 17:15 ` Chris Torek
  0 siblings, 1 reply; 4+ messages in thread
From: Yuri @ 2021-09-05 17:09 UTC (permalink / raw)
  To: Git Mailing List

In one sub-directory I altered some files, added a directory with files 
and added the changes (git add .)

Then I called 'git stash push && git stash pop'.

After this the newly added directory remained in the staged status, but 
altered files became unstaged.

Is this an intended behavior?

Why stash push/pop unstages files? Shouldn't it preserve the directory 
as-is?


Thanks,

Yuri



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: stash push/pop unstages files?
  2021-09-05 17:09 stash push/pop unstages files? Yuri
@ 2021-09-05 17:15 ` Chris Torek
  2021-09-05 19:02   ` Yuri
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Torek @ 2021-09-05 17:15 UTC (permalink / raw)
  To: Yuri; +Cc: Git Mailing List

On Sun, Sep 5, 2021 at 10:12 AM Yuri <yuri@rawbw.com> wrote:
> In one sub-directory I altered some files, added a directory with files
> and added the changes (git add .)
>
> Then I called 'git stash push && git stash pop'.
>
> After this the newly added directory remained in the staged status, but
> altered files became unstaged.
>
> Is this an intended behavior?

Yes.

> Why stash push/pop unstages files? Shouldn't it preserve the directory
> as-is?

It does, *provided* you invoke the pop step with `--index`.

When `git stash push` makes a stash, it saves both the index
(staging area) and working tree, as two separate commits.

Later, at the time you apply the saved stash, you choose
whether to use the saved index / staging-area (`--index`) or to
discard it (no `--index`).  The apply step uses the saved working
tree in all cases, and if you also stashed untracked files with
`-u` or `-a`, it uses this third commit as well.

The `pop` command is just `apply` followed by `drop` if the
application succeeds.

Chris

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: stash push/pop unstages files?
  2021-09-05 17:15 ` Chris Torek
@ 2021-09-05 19:02   ` Yuri
  2021-09-05 19:19     ` Chris Torek
  0 siblings, 1 reply; 4+ messages in thread
From: Yuri @ 2021-09-05 19:02 UTC (permalink / raw)
  To: Chris Torek; +Cc: Git Mailing List

On 9/5/21 10:15 AM, Chris Torek wrote:
> It does,*provided*  you invoke the pop step with `--index`.
>
> When `git stash push` makes a stash, it saves both the index
> (staging area) and working tree, as two separate commits.


Why 'stash push' and 'stash pop' are asymmetric in what they do by default?
Wouldn't it make more sense to make 'stash pop' precisely revert what 
'stash push' does, and have an option '--no-index' instead?


Yuri



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: stash push/pop unstages files?
  2021-09-05 19:02   ` Yuri
@ 2021-09-05 19:19     ` Chris Torek
  0 siblings, 0 replies; 4+ messages in thread
From: Chris Torek @ 2021-09-05 19:19 UTC (permalink / raw)
  To: Yuri; +Cc: Git Mailing List

On Sun, Sep 5, 2021 at 12:02 PM Yuri <yuri@rawbw.com> wrote:
> Why 'stash push' and 'stash pop' are asymmetric in what they do by default?
> Wouldn't it make more sense to make 'stash pop' precisely revert what
> 'stash push' does, and have an option '--no-index' instead?

If you ask me, yes, it would—but it would make even *more* sense
if `git stash` didn't bother saving the index at all without `--index`, and
just errored out if the index and working tree didn't match.  But I didn't
write `git stash`.

My personal recommendation is: never (or hardly ever) use it.  Just
make a commit.

Chris

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-05 19:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-05 17:09 stash push/pop unstages files? Yuri
2021-09-05 17:15 ` Chris Torek
2021-09-05 19:02   ` Yuri
2021-09-05 19:19     ` Chris Torek

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).