From: Tanay Abhra <tanayabh@gmail.com>
To: git@vger.kernel.org
Subject: Re: [bug] [UX] `stash save --untracked` produces a stash that *looks* empty
Date: Wed, 08 Oct 2014 14:50:14 +0530 [thread overview]
Message-ID: <543501CE.5040705@gmail.com> (raw)
In-Reply-To: <CACsY31pSeijqGC4Rw=q+qAGHJQ+bNibindVReYoZZACvYL7O+A@mail.gmail.com>
On 10/5/2014 10:58 PM, Alberto Scotto wrote:
> Hi all,
>
> I've just found that:
> - given you have an empty staging area
> - and you have only untracked files in your working dir
> - when you do `git stash --untracked`
> - then `git stash show` gives you an empty output => stash looks empty
>
> My first thought was "oh god, my files are lost!"
> Second thought: "Jeez I found a bug in git! cool!"
> Then I found that actually `git stash apply` restores the apparently lost
> files
> So I think it's a UX issue.
> It cost me a few lost files already, as I thought "an empty stash? uhm..
> can't remember what/when I stashed.. whatever.. let's just delete it and
> clean up a little bit this mess of stashes".
>
>
> Here are the reproducible steps:
>
> 1. create new fresh git repo in $REPO_DIR
> 2. create a couple of files/dirs and commit
> 3. edit src/MyClass.java and commit
> 4. create dir src/new-dir with one file inside
> 5. edit file.txt and stage it
> 6. stash => stashes staged changes; only untracked files are left
> 7. stash -u => stashes untracked changes => working dir is clean
> 8. stash list
> 9. git stash show -p => empty output
> 10. git stash apply (restore stashed untracked files)
Hi,
I think problem lies with show_stash() which just shows the
diff between working tree and the base tree, it ignores the
untracked files. A quick and dirty fix can be to just show
the diff between the untracked files and a NULL commit.
Here's the patch, it works all right but can be implemented
much better. I will try to find a better approach tomorrow.
diff --git a/git-stash.sh b/git-stash.sh
index d4cf818..7088584 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -304,6 +304,8 @@ show_stash () {
assert_stash_like "$@"
git diff ${FLAGS:---stat} $b_commit $w_commit
+ empty_tree=$(git hash-object -t tree /dev/null)
+ git diff ${FLAGS:---stat} ${empty_tree} $u_commit
}
#
Cheers,
Tanay
next prev parent reply other threads:[~2014-10-08 9:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-05 17:28 [bug] [UX] `stash save --untracked` produces a stash that *looks* empty Alberto Scotto
2014-10-08 9:20 ` Tanay Abhra [this message]
2014-10-09 2:51 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=543501CE.5040705@gmail.com \
--to=tanayabh@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).