Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `git show` do all by itself?

Tags:

git

git-show

If I use git show all by itself in a git repo it shows a bunch of information such as commits, diffs, etc.

This page (https://git-scm.com/docs/git-show) just says:

Shows one or more objects (blobs, trees, tags and commits).

I assume it's the latest commit. And some diffs (which aren't mentioned in the docs page).

But what exactly is it showing?

Here's the full, rather incomprehensible, output...

$ git show
commit <sha1 A> (HEAD -> A)
Merge: <sha1 B> <sha1 C>
Author: Snowcrash <my@email>
Date:   Sat Jul 14 14:56:02 2018 -0700

    with both files

diff --cc 1
index <sha1 D>,<sha1 E>..<sha1 F>
--- a/1
+++ b/1
@@@ -1,5 -1,6 +1,12 @@@
  1

++<<<<<<< HEAD
 +A
 +B
 +C
++=======
+ C
+ D
+ E
+
++>>>>>>> master
diff --cc 2
index 0000000,0000000..<sha1 G>
new file mode 100644
--- /dev/null
+++ b/2
@@@ -1,0 -1,0 +1,1 @@@
++2
like image 410
Snowcrash Avatar asked Jul 14 '18 22:07

Snowcrash


People also ask

Does git diff show all changes?

The git diff command returns a list of all the changes in all the files between our last commit and our current repository. If you want to retrieve the changes made to a specific file in a repository, you can specify that file as a third parameter.

Which command will show you all the commands possible with git?

The Git status command gives us all the necessary information about the current branch.

How does git know which changes to keep?

To determine whether a file has changed, Git compares its current stats with those cached in the index. If they match, then Git can skip reading the file again. Since stat calls are considerably faster than file reads, if you only edit a few files, Git can update its state in almost no time.

How do I see all commits?

On GitHub.com, you can access your project history by selecting the commit button from the code tab on your project. Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.


1 Answers

As emlai wrote, git show describes the HEAD commit by default. As for what it shows about the HEAD commit, the git-show manual page describes the output:

For commits it shows the log message and textual diff. It also presents the merge commit in a special format as produced by git diff-tree --cc.

At least for non-merge commits, this output is the same as the output from git log --cc HEAD~..HEAD. The --cc flag causes the diff to be shown.

like image 87
Rory O'Kane Avatar answered Sep 21 '22 23:09

Rory O'Kane