threads / discuss / 10091

suggestion for git stash

Subject: suggestion for git stash

## tl;dr

6 messages between Sep 30, 2007 and Sep 30, 2007.

replies: 5people: 5as markdown or json

Bruno Haible· Sep 30, 2007, 18:50 UTC · lore
Hi,

"git stash" has the effect of losing the distinction between untracked changes and changes in the index.

To reproduce:
- Clone the gnulib repository or of any repository with at least 2 files.
- Make changes to two files, say, README and NEWS.
  $ git add README
- $ git status
  now reports:
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   README
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#
#       modified:   NEWS
#
- $ git stash
- $ git stash apply
- $ git status
  now reports:
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#
#       modified:   NEWS
#       modified:   README
#
no changes added to commit (use "git add" and/or "git commit -a")

Could "git stash" be changed to memorize which changes were already scheduled for commit and which didn't?

Bruno
Matthieu Moy· Sep 30, 2007, 20:28 UTC · re: Junio C Hamano · lore

Re: suggestion for git stash

Junio C Hamano <gitster@pobox.com> writes:
> Isn't "stash apply --index" what you talk about?

It doesn't seem to be documented in Documentation/git-stash.txt, but seems to be the answer.

-- 
Matthieu
Bruno Haible· Sep 30, 2007, 20:59 UTC · re: Junio C Hamano · lore

Re: suggestion for git stash

Junio C Hamano wrote:
> Isn't "stash apply --index" what you talk about?
Not really:

$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: README # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # # modified: NEWS # $ git stash Saved "WIP on master: 61135ee... Use check_PROGRAMS instead of noinst_PROGRAMS." HEAD is now at 61135ee... Use check_PROGRAMS instead of noinst_PROGRAMS. $ git stash apply --index error: No changes Conflicts in index. Try without --index.

(This is git version 1.5.3.1.)
I don't know what "git stash apply --index" does, since it's not documented.
Bruno
Johannes Schindelin· Sep 30, 2007, 21:29 UTC · re: Bruno Haible · lore

Re: suggestion for git stash

Hi,
On Sun, 30 Sep 2007, Bruno Haible wrote:
> I don't know what "git stash apply --index" does, since it's not 
> documented.
It's documented in code ;-)

No, really, what it does is trying to reinstate not only the working tree's changes, but also the index' ones. However, this can fail, when you have conflicts (which are stored in the index, where you therefore can no longer apply the changes as they were originally).

Now that you know what --index is supposed to do, maybe you are nice enough to extend the documentation and post a patch?

Thanks, Dscho

Miklos Vajna· Sep 30, 2007, 22:30 UTC · re: Johannes Schindelin · lore

[PATCH] git stash: document apply's --index switch

---
On Sun, Sep 30, 2007 at 10:29:05PM +0100, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> Now that you know what --index is supposed to do, maybe you are nice
> enough to extend the documentation and post a patch?
something like this?
VMiklos
 Documentation/git-stash.txt |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index 05f40cf..5723bb0 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -63,7 +63,7 @@ show [<stash>]::
 	it will accept any format known to `git-diff` (e.g., `git-stash show
 	-p stash@\{1}` to view the second most recent stash in patch form).
 
-apply [<stash>]::
+apply [--index] [<stash>]::
 
 	Restore the changes recorded in the stash on top of the current
 	working tree state.  When no `<stash>` is given, applies the latest
@@ -71,6 +71,11 @@ apply [<stash>]::
 +
 This operation can fail with conflicts; you need to resolve them
 by hand in the working tree.
++
+If the `--index` option is used, then tries to reinstate not only the working
+tree's changes, but also the index's ones. However, this can fail, when you
+have conflicts (which are stored in the index, where you therefore can no
+longer apply the changes as they were originally).
 
 clear::
 	Remove all the stashed states. Note that those states will then
-- 
1.5.3.2.111.g5166-dirty

← back to recent threads