Saving a permanent snapshot with git commit, writing professional commit messages in Conventional Commits format, reading history with git log, and fixing the last commit using git commit --amend.

In episode 3 you initialized a repository and staged files into the staging area. But staged files are not truly safe yet — they are still "floating" in the intermediate area. Commit is the action that moves them into permanent storage.
A commit is the smallest unit of a project's history. Each commit is like a point on a timeline: when it was made, by whom, what changed, and a message explaining why. The ability to write good commits is a skill that separates professional developers.
Make sure your changes are staged, then run:
git add index.html
git commit -m "feat: tambah halaman index"The git commit -m "pesan" command creates a snapshot of the staging area and saves it to the repository, complete with author, timestamp, and the message you provide. After committing, run git status to see the result:
git status
On branch main
nothing to commit, working tree cleanTip
working tree clean is a reassuring phrase — it means no changes are left behind and the repository is in a consistent state. Get in the habit of ending work sessions in this state.
Remember episode 2: a commit stores a pointer to a tree (snapshot), author metadata, timestamp, message, and a pointer to the parent commit. This means a commit is a "timestamp label" — you can return to the exact state at the moment of the commit, any time.
A good commit message answers one question: why does this change exist? The Conventional Commits specification provides a standard format used across the industry and serves as the basis for automated versioning (SemVer).
feat: tambah halaman login
fix(auth): perbaiki null pointer saat logout| Type | Usage |
|---|---|
feat | New feature |
fix | Bug fix |
docs | Documentation change |
refactor | Refactor without changing behavior |
chore | Maintenance, build, dependency tasks |
The feat and fix types are very important for projects using semantic-release: they determine whether the version bumps MAJOR/MINOR. An optional scope (like (auth)) marks the affected part of the code.
Warning
Avoid generic messages like update or fix bug. Future teammates — including yourself six months from now — will thank you when git log clearly explains what and why.
git log is the window into the entire repository history. Some of the most useful options:
git log --oneline --graph --all
* 9c4a2d6e chore: update dependency
* b8e1f3a7 feat: tambah halaman login
* a7b8c9d0 Initial commit--oneline — each commit on a single line (short hash + message).--graph — shows branch visualization.--all — shows history of all branches, not just the active one.--stat — shows the stats of changed files per commit.-n <count> — limits the number of commits, e.g. git log -n 5.git log -n 1 --stat
b8e1f3a7 feat: tambah halaman login
login.js | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)It often happens after a commit is made: the message has a typo, or one file was left out. git commit --amend allows you to change the last commit — as long as that commit has not been pushed to a remote yet.
git commit --amend -m "feat: tambah halaman login dengan validasi"Adding a file that was left out of the last commit:
git add login.test.js
git commit --amend --no-edit--no-edit keeps the commit message the same — it only replaces the commit's content. Important note: --amend replaces the old commit with a new one (the hash changes), so do not use it on commits already shared publicly.
Warning
Git's golden rule: never rewrite history that has already been published. git commit --amend is only safe for local commits that have not been pushed. For public history, use git revert (details in episode 14).
Episode 4 recap:
git commit -m permanently saves the staging area snapshot.feat, fix, docs, refactor, chore.git log with --oneline, --graph, --all, --stat, -n opens up the entire history.git commit --amend fixes the message or adds files to the last unpushed commit.In episode 5 we learn comparing changes: git diff between areas, git diff --staged, comparisons between commits, inspecting commit details with git show, and identifying the author of each line of code with git blame. These are investigative skills you will use every day as a developer. See you there!