Git & GitHub
/Intermediate
git show
Definition
Shows one or more objects (blobs, trees, tags and commits). Most commonly used to see the exact code changes introduced by a specific commit.
Explain Like I'm New
`git log` tells you THAT a commit happened. `git show` tells you exactly WHAT code was added or deleted inside that commit.
Real World Example
You see a commit titled 'Fix header'. You type `git show <hash>` to see exactly which CSS lines were changed to fix the header.
Common Use Cases
- •Code review
- •Investigating past changes in detail
`git show` Flags
| Flag | Description |
|---|---|
| `git show [commit_hash]` | Shows the log message and textual diff of the specific commit. |
| `--stat` | Shows only the list of modified files and how many lines were added/removed. |
| `--name-only` | Shows only the raw file names that were changed. |
| `HEAD` | Shows the very last commit you made. |
Terminal Output
bash / terminal
# Show the exact code changes of the most recent commit
$ git show
# Show the exact code changes of a specific commit from history
$ git show a1b2c3d
/* Output Example:
commit a1b2c3d
Author: John Doe
diff --git a/styles.css b/styles.css
@@ -10,3 +10,4 @@
.header {
- background: blue;
+ background: red;
+ font-weight: bold;
}
*/
Interview Questions
basic
- If you just type `git show` without a hash, what does it show?
intermediate
- In the output of `git show`, what do lines starting with `+` and `-` mean?