# Git Log and Git Diff

> How to read the history you saved. What a good commit message looks like, what the long commit hash is, and how a diff shows each changed line.

**Course:** [Git and GitHub](https://learn.benibix.com/learn/development-version-control)  
**Time:** 12 min

**After this lesson you can:**

- Write a commit message people can use
- Find a commit with git log
- Read the lines in a diff

## How to read your project's history

Git log lists every commit in your project, newest first. Each entry shows a long ID called the commit hash, the author, the date and the message. The hash is 40 letters and numbers long, but the first 7 are almost always enough. Git log --oneline shows just those 7 and the first line of the message.

The hash is worked out from all that is in the commit: the changes, the author, the time, the message and the commit before it. Change any of those and you get a new hash. That is how Git spots damage. It is also why a commit is never edited in place, only replaced.

A commit message is the note you write for each commit. Git's own advice is a first line of no more than 50 characters, then a blank line, then more detail if it is needed. The first line is the title that tools show in lists. Write it as what the commit does, such as Fix the price on the order page.

The body is where the why goes. The change itself shows what is different. It cannot show that coupons made the tax appear twice, or that a customer asked for it. Six months later, the why is the part nobody can rebuild from the code alone.

A diff shows the exact lines that changed between two versions. Lines that were taken out start with a minus sign. Lines that were added start with a plus sign. A changed line shows up as both: the old one with a minus, then the new one with a plus.

Git diff on its own shows the changes you have not staged yet. Git diff --staged shows what is about to go into the next commit. Reading that second one before each commit is the habit that catches stray test lines and secrets.

Scrolling a long log by hand is slow, so let git log filter it. Add a file name to see only the commits that touched that file. Add --author and a name to see one person's work. Add -3 to see only the last three.

Messages like fix, stuff or wip are the most common mistake. They make sense for an hour. A month later, the commit you need is one of forty that all say fix. A message is written once and read many times, so write it for the person reading.

```console
$ git diff
diff --git a/style.css b/style.css
index c0e1a88..c6129cb 100644
--- a/style.css
+++ b/style.css
@@ -1 +1 @@
-body{}
+body{color:blue}
$ git add style.css
$ git commit -m "Make the text blue"
[main f5557bd] Make the text blue
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git log --oneline
f5557bd Make the text blue
5de3e92 Add style sheet
a205dfe Add home page
```
Read the diff, commit it, then see it at the top of the log with its short hash.

![One commit drawn as a card. At the top, its hash, a long code of letters and numbers, with the first seven characters lit up as the short form. Below it, the author Emma and the date. Then the message: a title line under 50 characters, a blank line, and a body that says why. To the right, git log lists three commits, newest first, each as a short hash and its title.](https://learn.benibix.com/diagrams/dev3-commit-anatomy.svg)

### Example: Emma hunts down a price bug

Emma's shop has shown wrong prices since Tuesday. She runs git log on the file price.js and gets 4 commits from the last week.

One from Monday says Round prices to whole euros. Its diff shows round(price, 2) turned into round(price). She has the cause in 5 minutes.

**Words in this lesson:** [Commit Message](https://learn.benibix.com/term/development/commit-message), [Commit Hash](https://learn.benibix.com/term/development/commit-hash), [Git Log](https://learn.benibix.com/term/development/git-log), [Diff](https://learn.benibix.com/term/development/diff)

**Question:** Why does a commit get a new hash when I change its message?

**Answer:** The hash is worked out from the commit's content, message included. The hash comes from all of the commit, including the message and the commit before it. Change any part and the hash changes. So the commit is really a new one.

---

Source: https://learn.benibix.com/learn/development-version-control/git-log-and-git-diff
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
