See Code Changes

Here’s the thing no one told me early on: Git isn’t just about saving code—it’s about understanding your code’s story. What changed, when, why, and by whom. And if you’re anything like me, you’ll sometimes stare at a broken feature and think, “Wait, it was working yesterday… What did I do??”

That’s where git diff and git log come in. These tools are your time machine and your magnifying glass rolled into one. Whether you’re debugging a nasty bug or reviewing your teammate’s changes, learning to read your Git history is essential.

How I Use `git diff` Before Every Commit (and Why You Should Too)

True story: I once committed a bunch of console.log() statements to production. I was moving fast, didn’t check what I staged, and boom—shipwreck. Ever since, I run git diff every single time before committing.

Want to see what you’ve changed but haven’t staged yet?

bash
1
          git diff
        

This command compares your working directory with the last commit. It literally shows you a line-by-line breakdown—so no surprises later.

Already ran git add and want to review what’s staged?

bash
1
          git diff --cached
        

Here’s where it gets even cooler. Want to compare two random commits from last week?

bash
1
          git diff commit1 commit2
        

That’s perfect for when you’re tracking down bugs that suddenly appeared. (Spoiler alert: it was usually me from 3 days ago.)

There’s also GitLens if you're using VS Code—it visualizes this kind of stuff beautifully.

Peek Into the Past with `git log` (Your Project’s Memory Bank)

Git stores every commit like a diary entry. When you want to see who did what, when, and why, type:

bash
1
          git log
        

You’ll get a full history of your project: commit hashes, authors, dates, and messages. It’s raw, but super useful.

Want a cleaner version that’s easier on the eyes?

bash
1
          git log --oneline
        

This is great for scanning recent commits without the clutter. Sometimes I even use it just to remind myself what I was working on last week.

Oh, and if you're tracking changes to a particular file (maybe app.js is acting weird):

bash
1
          git log app.js
        

Boom. Now you know exactly when that file changed—and who to blame. (Just kidding, be kind. Even if it's yourself.)

Reading `git diff` Output Without Losing Your Sanity

When you first see git diff output, it might look like computer Matrix code. But here’s the cheat sheet:

  • Lines starting with - were removed
  • Lines starting with + were added
  • Everything else is context

Once you understand that, it’s actually pretty easy to read. You can literally watch your code evolve, like DNA mutating in real time (except, hopefully, with fewer bugs).

Pairing git log with git diff lets you trace back a bug’s origin like a forensic detective. It’s honestly satisfying once you get the hang of it.

Wrapping Up: Git Isn't Just Version Control—It's Code Clarity

Learning git diff and git log changed the way I debug and review code. Instead of guessing what broke or assuming what changed, I just ask Git. It's like talking to your past self—with receipts.

In the next chapter, we're stepping into the world of GitHub—where your local Git powers meet the real world. You’ll learn how to share your work, collaborate with others, and manage code like a pro on the cloud. But first, we will learn how to Create a GitHub Repo

It's about to get real. And a little more public. 😅