Basic

What a commit actually does to your history

A repository on GitHub is just a folder of your project, living in the cloud, and every change you keep is saved as a commit. Think of a commit as a snapshot with a sticky note attached. Later you can flip back through all of them, one at a time, and see exactly what the project looked like and when.

What you will see

commit abc1234... Author: You <you@example.com> Date: now Log modal button in changelog CHANGELOG.md | 1 insertion(+)

About 2 min of reading

Try It

I changed the homepage and committed it, but I did not know how many lines git had actually saved or why it said what it said. Let me make a real edit, stage it, and watch a commit become the first entry in a history I can read back months later.

1

Make a real change to a file that already exists and nothing else. The moment after I write the new line, git considers the file modified, but it is not yet saved into history. git status is the exact thing I look at before every commit, it tells me what is changed and what is not.

echo "Button now opens a modal on click" > CHANGELOG.md git status

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Changes not staged for commit: modified: CHANGELOG.md
The modification exists on disk but git has not staged it yet. It shows as "not staged for commit", which is normal before the next line.
2

git add moves that change into staging, the limbo the lesson describes. It is the single command that decides what goes into this snapshot, so I stage just the one file I edited, not everything that might be lying around.

git add CHANGELOG.md git status

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Changes to be committed: modified: CHANGELOG.md
git add does not commit the change. It only moves it into staging. If I forgot to add it, the commit below would be empty and git would refuse.
3

Write the message that becomes the sticky note on this commit. The one I wrote says what changed and where, so a teammate (or future me) reading the history later does not have to guess. Pick one and commit.

git commit -m "Log modal button in changelog"

Before you run it, say out loud what it will print. Then open the answer.

What it prints
[main abc1234] Log modal button in changelog 1 file changed, 1 insertion(+)
A commit with no message is rejected. If the branch is not called main in your repo, the message before the verb will show your branch name instead of main.
4

This is the reply I was curious about. git log --oneline prints the whole history, newest at the bottom, oldest at the top, with a short ID and each message you wrote. My new commit is now the newest line, and everything before it is still there.

git log --oneline

Before you run it, say out loud what it will print. Then open the answer.

What it prints
abc1234 Log modal button in changelog 1111111 Initial commit
The short ID changes every time; git hashes the whole commit, so a different message means a different ID. Only the message is what I control.
5

Confirm the snapshot is really there. git show prints the exact contents of the most recent commit, the files it touched and every added and removed line. If the log looked right but I wanted proof of what actually landed, this is the line I run.

git show --stat

Before you run it, say out loud what it will print. Then open the answer.

What it prints
commit abc1234... Author: You Date: now Log modal button in changelog CHANGELOG.md | 1 insertion(+)
git show defaults to HEAD, the latest commit. If there are several commits to inspect, point it at a specific short ID to see an older one instead.

Data Flow

Edit files, stage what you want to save, write a short message, then commit.
1 Edit files
↓
2 Stage them with git add
↓
3 Write a message that explains the change
↓
4 Commit
Why this works
What a repo holds

A repo keeps all your files, their full history, and a message describing each change. It's the single source of truth everyone on the project can fall back to when they can't remember what changed and why.

Why commit often

Small, frequent commits are easy to read in hindsight, and they're your safety net: if one bad change sneaks in, you can undo just that commit without throwing away everything since it.

Examples

Committing your first real change

You: "I changed the homepage."
git add index.html
git commit -m "Fix the homepage button color"

git replies with something short and satisfying: 1 file changed, 10 lines added. Each commit makes a snapshot of your work at that moment. Months later you can open the history and read every message, and it tells the story of how the project grew.

Staging before you commit

git add app.js
git status

Before you commit, changes sit in a limbo called staging. git add moves a file into that limbo. It's a bit like packing boxes before the movers arrive: you get to decide exactly what goes into this snapshot and what stays for later.

Staging is also how you split one edit into several commits. Change three things but only want to commit one of them? Stage that one, leave the rest.

Reading the history like a timeline

git log --oneline

This prints your commit history, oldest at the top, newest at the bottom. Each line has a short ID and the message you wrote. It's a quick way to answer the question nobody likes to ask: what did I actually change last week?

Read enough history and you start to see your own habits, the messy commits during a rough day, the clean ones when you knew what you were doing.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

Next Lesson
Why you never work directly on main
Why you never work directly on main →