git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Viewing untracked+stashed files in git stash show

From
Jeff King <peff@peff.net>
Date
Mar 17, 2017, 14:14 UTC
Message-ID
<20170317141417.g2oenl67k74nlqrq@sigill.intra.peff.net>
In-Reply-To
<20170317135144.scnbtyug2cqbg77p@sigill.intra.peff.net>
On Fri, Mar 17, 2017 at 09:51:44AM -0400, Jeff King wrote:
Show 18 quoted lines
> > 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
Previous: Jeff King
Message 6 of 6 in “Viewing untracked+stashed files in git stash show”
  1. Okash KhawajaMar 16, 2017
  2. stefan.naewe@atlas-elektronik.comMar 17, 2017
  3. Okash KhawajaMar 17, 2017
  4. Okash KhawajaMar 17, 2017
  5. Jeff KingMar 17, 2017
  6. Jeff KingMar 17, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.