Trending
| 9:58 PM IST
Git status, Git log and Git diff: Reading Your Project's History (Part 8)
Tech

Git status, Git log and Git diff: Reading Your Project's History (Part 8)

Three commands let you see everything about your project: git status for now, git log for the past and git diff for exact changes. Part 8 of our visual Git and GitHub series.

By · 9 min read 1 view Rate it 0 comments

Use git status to see what has changed right now, git log to see the history of commits, and git diff to see the exact lines that changed. Together, these three read-only commands answer almost every "what happened to my project?" question, and they never change your files, so they are always safe to run.

Two weeks after her first commit, Sneha's uncle phoned: "The WhatsApp button on the bakery site has disappeared! When did that happen?" A month earlier, she would have panicked. This time she opened her terminal, typed three commands and found the answer in under a minute: the button vanished in Tuesday's commit "Redesign footer", when she accidentally deleted one line. In Part 7 you made your first commits. This Part 8 opens Module 3, the daily workflow, by teaching you the same detective skills Sneha used.

Your one-minute summary

  • git status: the present, which files are changed, staged or new
  • git log: the past, the list of commits with IDs and messages
  • git diff: the details, line-by-line changes in red and green
  • git diff --staged shows what is about to be committed
  • git show <id> shows one commit in full
  • All of these are read-only; they never change your files

What do git status, git log and git diff each do?

Think of them as three questions you ask Git. Each gives a different view of the same project.

Three questions, three commands

git status: "What is going on now?"

  • Changed but not staged files
  • Staged files ready to commit
  • New untracked files
  • Which branch you are on

git log: "What happened before?"

  • Every commit, newest first
  • ID, author, date, message
  • Filter by date, person or file

git diff: "What exactly changed?"

  • Line-by-line differences
  • Red minus lines removed
  • Green plus lines added

How do I read git status?

git status groups your files by the three areas from Part 4. Here is a typical reply, translated:

Git saysPlain meaningArea
On branch mainYou are working on the main line(branch)
Changes to be committed: modified: index.htmlindex.html is in the box, ready to commitStaging area
Changes not staged for commit: modified: style.cssstyle.css is edited but not in the box yetWorking folder
Untracked files: about.htmlA new file Git is not recording yetWorking folder
nothing to commit, working tree cleanEverything is saved; no changes since the last commitAll in sync
Shortcutgit status -s gives a compact view: M means modified, A means added (staged new file) and ?? means untracked. The column the letter is in tells you if it is staged (left) or not (right).
Also readYour First Git Repository and First Commit, Step by Step (Part 7)

How do I read git log?

git log lists commits from newest to oldest. The full version shows a lot; these variations are more useful day to day:

CommandWhat you see
git logFull details: ID, author, date, message for every commit (press q to quit)
git log --onelineOne line per commit: short ID and message
git log --oneline --graphAdds a drawing of branches and merges (useful from Part 12)
git log -5Only the last 5 commits
git log --since="2 weeks ago"Commits from the last two weeks
git log --author="Sneha"Commits by one person
git log -- index.htmlOnly commits that changed index.html

Sneha's investigation, step by step

git log --oneline -- index.htmlLists the 4 commits that touched the homepage
Spots "7c1d2e9 Redesign footer" from TuesdayThe most likely suspect
git show 7c1d2e9Shows that commit's message and diff
Finds a red line: the WhatsApp linkDeleted by accident while editing the footer
Adds it back and commits "Restore WhatsApp button"Uncle happy, total time under five minutes
Stuck in git log?Long logs open in a scrolling viewer. Use the arrow keys or Space to scroll and press q to quit. Nothing is broken.

How do I read git diff?

git diff shows line-by-line changes. Which changes it compares depends on how you call it, and this trips up many beginners.

Which diff do I need?

git diffWorking folder vs staging area: changes you have not staged yet
git diff --stagedStaging area vs last commit: what your next commit will contain
git diff HEADAll changes since the last commit, staged or not
git diff 1a2b3c4 3f9a2c1Compare any two commits
git show 3f9a2c1One commit: its message plus its diff

How do I read a diff's output?

A diff looks scary until you know its parts. Here is a small example after changing a heading:

Diff lineMeaning
diff --git a/index.html b/index.htmlWhich file is being compared
@@ -3,1 +3,1 @@Where in the file: around line 3
-<h1>Hi, I am Sneha</h1>Removed line (red)
+<h1>Namaste, I am Sneha</h1>Added line (green)

Git does not "edit" lines; it shows a changed line as one removal plus one addition. That is why a small change appears as a red line followed by a green line.

What is HEAD?

HEAD is Git's name for "where you are now", usually the latest commit on your current branch. HEAD~1 means "one commit before HEAD", HEAD~2 means two before, and so on. So git diff HEAD~1 compares your files with the previous commit.

Counting back from HEAD

HEADThe latest commit: "Restore WhatsApp button"
HEAD~1One before: "Redesign footer"
HEAD~2Two before: "Add festival offers banner"
HEAD~3Three before: "Order form works"

Can I see history without the terminal?

Yes, and the visual views are excellent for beginners:

  • VS Code: the Source Control panel shows changes; click a file for a side-by-side diff. The Timeline section in the Explorer lists commits that touched the open file.
  • GitHub Desktop: the Changes tab is your git status and git diff; the History tab is your git log.
  • GitHub.com: after pushing (Part 9), click the commit count on your repository page to browse history, and click any commit to see its coloured diff.

Same information, four places

Terminalgit status, git log, git diff
VS CodeSource Control panel and Timeline
GitHub DesktopChanges tab and History tab
GitHub.comCommits page and coloured commit view

How do these commands help in real life?

  • "The site broke after lunch." Run git diff to see everything you changed since the last commit.
  • "When did the WhatsApp button disappear?" Run git log -- index.html and check commits that touched the page.
  • "What did the AI tool change?" Run git diff after the AI finishes, before you commit.
  • "Am I about to commit something silly?" Run git diff --staged before every commit.

Before Part 9, make sure you can

  • Explain the three groups git status shows
  • Use git log --oneline and quit a long log with q
  • Tell the difference between git diff and git diff --staged
  • Read a diff: red minus removed, green plus added
  • Say what HEAD and HEAD~1 mean

Her View

There is something reassuring about being able to see exactly what changed. It replaces the anxious "what did I do?" feeling with calm facts. When something goes wrong, you are no longer guessing; you are reading. That shift, from panic to investigation, is one of the quiet gifts Git gives every learner.

Also readHow to Install Git, VS Code and GitHub Desktop on Windows and Mac (Part 5)

His Insight

Make git diff --staged your last step before every commit. It takes five seconds and catches stray debug lines, accidental deletions and files you did not mean to include. Combined with clear commit messages, it turns git log into a reliable record you can search months later.

H View Verdict

git status shows the present, git log the past and git diff the details. They are safe, read-only and useful every single day. Now that you can read your history, it is time to share it. In Part 9, we connect your project to GitHub with git push, git pull and git clone.

Self-assessment: test yourself

Ready? Tap an option for each question. You will see right away whether you got it, with a short explanation, and your score at the end. Take your time, and try again as often as you like.

Status, log and diff quiz: 10 questions

1. Which command shows what will go into your next commit?

  1. git diff
  2. git diff --staged
  3. git log
  4. git push

git diff --staged compares the staging area with the last commit.

2. How do you exit a long git log?

  1. Ctrl + S
  2. Press q
  3. Close the laptop
  4. Type exit()

Git's viewer quits when you press q.

3. "Untracked files" in git status means

  1. Deleted files
  2. New files Git is not recording yet
  3. Files on GitHub
  4. Staged files

Untracked files are new; use git add to start tracking them.

4. What does HEAD usually point to?

  1. The first commit
  2. The latest commit on your current branch
  3. GitHub's server
  4. The staging area

HEAD means "where you are now", normally the newest commit on your branch.

5. Do git status, git log and git diff change your files?

  1. Yes, always
  2. Only git diff
  3. No, they are read-only
  4. Only on Windows

These commands only show information; they are always safe.

6. Which command lists only commits that changed index.html?

  1. git status index.html
  2. git log -- index.html
  3. git diff --all
  4. git add index.html

Adding -- and a file name filters the log to that file.

7. What does HEAD~1 mean?

  1. The first commit ever
  2. One commit before the latest
  3. The next commit
  4. A branch name

The tilde counts back from HEAD.

8. In git status -s, what does ?? mean?

  1. Git is confused
  2. Untracked file
  3. Merge conflict
  4. Deleted file

?? marks files Git is not tracking yet.

9. Which command shows one commit's message and its changes together?

  1. git show <id>
  2. git init
  3. git clone
  4. git branch

git show displays a commit with its diff.

10. In GitHub Desktop, which tab is the equivalent of git log?

  1. Changes
  2. History
  3. Settings
  4. Repository

The History tab lists your commits.

Frequently asked questions

Why does git diff show nothing?

Either there are no changes, or your changes are already staged. Try git diff --staged or git status.

How do I see who changed a specific line?

Use git blame filename. It shows the commit and author for each line. On GitHub, open the file and click "Blame".

Can I search commit messages?

Yes. git log --grep="contact" lists commits whose messages contain "contact".

Is git log the same on GitHub?

The history is the same once you push. GitHub shows it on the commits page with a friendlier layout.

Part 8 of 20 in our Git and GitHub for Beginners series. A small tip from us: run git status so often that it becomes a reflex. Next up, Part 9: git push, git pull and git clone, syncing with GitHub.
Topics: Tech
Harika Behara

Writes for H View, where every story follows our editorial policy and is reviewed before it is published.

All stories by Harika →

H View stories follow our editorial policy. Spotted an error? Tell us and we will correct it.

Rate this article

One tap is enough. No comment needed.

Your rating
Be the first to rate it.

Was this article helpful?

Your answer goes straight to our editors.

Comments0

Be kind and stay on topic. Comments with links are checked before they appear.

No comments yet. Start the conversation.

The H View Brief

Our best stories, in your inbox.

The week’s best Her View, His Insight reading in one short, useful note.

Free. We only use your email to send The H View Brief. Unsubscribe any time.