From: Jeff King <peff@peff.net>
To: Okash Khawaja <okash.khawaja@gmail.com>
Cc: stefan.naewe@atlas-elektronik.com, git@vger.kernel.org
Subject: Re: Viewing untracked+stashed files in git stash show
Date: Fri, 17 Mar 2017 10:14:17 -0400 [thread overview]
Message-ID: <20170317141417.g2oenl67k74nlqrq@sigill.intra.peff.net> (raw)
In-Reply-To: <20170317135144.scnbtyug2cqbg77p@sigill.intra.peff.net>
On Fri, Mar 17, 2017 at 09:51:44AM -0400, Jeff King wrote:
> > Okay that's fine as long as you know. But the first thing that comes
> > to your mind is that you've lost those untracked files. Is there a
> > reason why git stash show doesn't show those files?
>
> No, I don't think there is a good reason. The "untracked" option was
> added to git-stash much later, and nobody considered how it interacted
> with "stash show".
>
> Changes from the index have the same problem. Probably "stash show"
> should have options "--index" and "--untracked" to show:
>
> # index
> git diff $stash^1 $stash^2
>
> # untracked
> git diff $stash^1 $stash^3
>
> Possibly it should even show those by default when they are non-empty.
Actually, $stash^1 is already the parent of the other commits, so we can
just show them as-is. Doing this:
diff --git a/git-stash.sh b/git-stash.sh
index 9c70662cc..868d9027b 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -388,7 +388,16 @@ show_stash () {
fi
fi
- git diff ${FLAGS} $b_commit $w_commit
+ {
+ # use --pretty=format instead of tformat, because it omits the
+ # blank line between the subject and the diff; use "."
+ # to enable history simplification and drop empty commits.
+ git show --first-parent -m --pretty=format:'==> %s <==' \
+ ${FLAGS} $w_commit -- .
+ git show --pretty=format:'%n==> %s <==' ${FLAGS} $i_commit -- .
+ test -n "$u_commit" &&
+ git show --pretty=format:'%n==> %s <==' ${FLAGS} $u_commit -- .
+ } | git_pager
}
show_help () {
actually looks OK to me, though I don't know if people really like the
existing format. With a setup like:
git init
echo base >file
git add file
git commit -m base
echo index >file
git add file
echo working tree >file
echo untracked >other
git stash -u
it looks like:
$ git stash show
==> WIP on master: 8aa1ec9 base <==
file | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
==> index on master: 8aa1ec9 base <==
file | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
==> untracked files on master: 8aa1ec9 base <==
other | 1 +
1 file changed, 1 insertion(+)
or:
$ git stash show -p
==> WIP on master: 8aa1ec9 base <==
diff --git a/file b/file
index df967b9..ace4bb6 100644
--- a/file
+++ b/file
@@ -1 +1 @@
-base
+working tree
==> index on master: 8aa1ec9 base <==
diff --git a/file b/file
index df967b9..9015a7a 100644
--- a/file
+++ b/file
@@ -1 +1 @@
-base
+index
==> untracked files on master: 8aa1ec9 base <==
diff --git a/other b/other
new file mode 100644
index 0000000..5a72eb2
--- /dev/null
+++ b/other
@@ -0,0 +1 @@
+untracked
And if you have only a single change, it omits the others:
$ echo working tree >file
$ git stash
$ git stash show
==> WIP on master: 8aa1ec9 base <==
file | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
If I were designing "stash show" from scratch today, I'd probably do
something like that. But like I said, I don't know if people are
invested in the current output (which _can_ be piped to "git apply" if
need be, though my output could, too, if you do not have index or
untracked files).
-Peff
prev parent reply other threads:[~2017-03-17 14:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-16 16:34 Viewing untracked+stashed files in git stash show Okash Khawaja
2017-03-17 8:20 ` stefan.naewe
2017-03-17 9:50 ` Okash Khawaja
2017-03-17 12:08 ` Okash Khawaja
2017-03-17 13:51 ` Jeff King
2017-03-17 14:14 ` Jeff King [this message]
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170317141417.g2oenl67k74nlqrq@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=okash.khawaja@gmail.com \
--cc=stefan.naewe@atlas-elektronik.com \
/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.
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).