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

Add a "git show" command to show a commit

From
Linus Torvalds <torvalds@osdl.org>
Date
Feb 5, 2006, 19:49 UTC
Message-ID
<Pine.LNX.4.64.0602051144580.3854@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.64.0602051141020.3854@g5.osdl.org>
It's basically just "git-diff-tree" with pretty flags and a pager.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

This uses the "--always" flag, btw, so it depends on the previous patch I sent. If you disagree with that, just remove it.

This is actually something I do pretty often, and I've grown tired of doing

	git-diff-tree -p --pretty cmit-id | less -S
so this is really nothing but a fairly flexible replacement for that.
It tries to have the same logic as "git diff" for the flags. 
diff --git a/Makefile b/Makefile
index 2aa2385..473e58d 100644
--- a/Makefile
+++ b/Makefile
@@ -112,7 +112,7 @@ SCRIPT_SH = \
 	git-applymbox.sh git-applypatch.sh git-am.sh \
 	git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
 	git-merge-resolve.sh git-merge-ours.sh git-grep.sh \
-	git-lost-found.sh
+	git-lost-found.sh git-show.sh
 
 SCRIPT_PERL = \
 	git-archimport.perl git-cvsimport.perl git-relink.perl \
diff --git a/git-show.sh b/git-show.sh
new file mode 100644
index 0000000..476bca4
--- /dev/null
+++ b/git-show.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+rev=$(git-rev-parse --verify --revs-only --no-flags --sq --default HEAD "$@") || exit
+flags=$(git-rev-parse --no-revs --flags --sq "$@")
+files=$(git-rev-parse --no-revs --no-flags --sq "$@")
+
+# Match the behaviour of "git diff":
+#  - if we do not have --name-status, --name-only nor -r, default to -p.
+#  - if we do not have -B nor -C, default to -M.
+case " $flags " in
+*" '--name-status' "* | *" '--name-only' "* | *" '-r' "* )
+	;;
+*)
+	flags="$flags'-p' " ;;
+esac
+case " $flags " in
+*" '-"[BCM]* | *" '--find-copies-harder' "*)
+	;; # something like -M50.
+*)
+	flags="$flags'-M' " ;;
+esac
+
+eval "git-diff-tree --always --cc --pretty $flags $rev -- $files" | LESS=-S ${PAGER:-less}
Previous: Linus TorvaldsNext: Linus Torvalds
Message 32 of 40 in “The merge from hell...”
  1. Linus TorvaldsFeb 2, 2006
  2. Junio C HamanoFeb 2, 2006
  3. combine-diff: reuse diff from the same blob.Junio C Hamano, Feb 2, 2006
  4. Linus TorvaldsFeb 2, 2006
  5. Linus TorvaldsFeb 2, 2006
  6. Linus TorvaldsFeb 2, 2006
  7. combine-diff: update --cc "uninteresting hunks" logic.Junio C Hamano, Feb 2, 2006
  8. combine-diff: add safety check to --cc.Junio C Hamano, Feb 2, 2006
  9. Linus TorvaldsFeb 2, 2006
  10. Junio C HamanoFeb 3, 2006
  11. Linus TorvaldsFeb 3, 2006
  12. [Attn - repository browser authors] diff-tree combined format.Junio C Hamano, Feb 3, 2006
  13. Marco CostalbaFeb 3, 2006
  14. Junio C HamanoFeb 3, 2006
  15. Junio C HamanoFeb 3, 2006
  16. Marco CostalbaFeb 4, 2006
  17. Paul MackerrasFeb 4, 2006
  18. Junio C HamanoFeb 3, 2006
  19. Paul MackerrasFeb 4, 2006
  20. Junio C HamanoFeb 4, 2006
  21. Paul MackerrasFeb 4, 2006
  22. Junio C HamanoFeb 4, 2006
  23. Linus TorvaldsFeb 4, 2006
  24. Linus TorvaldsFeb 4, 2006
  25. Marco CostalbaFeb 2, 2006
  26. Linus TorvaldsFeb 2, 2006
  27. Aneesh KumarFeb 2, 2006
  28. Junio C HamanoFeb 2, 2006
  29. Linus TorvaldsFeb 2, 2006
  30. Junio C HamanoFeb 2, 2006
  31. Linus TorvaldsFeb 5, 2006
  32. Add a "git show" command to show a commitLinus Torvalds, Feb 5, 2006
  33. Fix git-rev-parse over-eager errorsLinus Torvalds, Feb 5, 2006
  34. Junio C HamanoFeb 5, 2006
  35. Linus TorvaldsFeb 5, 2006
  36. Junio C HamanoFeb 6, 2006
  37. Junio C HamanoFeb 5, 2006
  38. Linus TorvaldsFeb 5, 2006
  39. Linus TorvaldsFeb 5, 2006
  40. Junio C HamanoFeb 6, 2006

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.