Learning bite
Commits and the working tree
Separate current files, staged changes, and recorded history.
On this page
Save an intentional version of your work
Git records versions of files so you can inspect what changed and return to known content. A repository is the history and configuration stored in .git, alongside the files you edit. Git is local software; a GitHub account or network connection is not needed for this module.
There are three places to distinguish:
| Place | Meaning | Inspect it |
|---|---|---|
| Working tree | Current files on disk, including unfinished edits | git status, git diff |
| Index, or staging area | File versions selected for the next commit | git diff --cached |
| Commit history | Recorded snapshots linked to earlier commits | git log, git show |
A commit is a snapshot, not merely the text of a diff. A diff is Git's presentation of the difference between two versions. Commits contain a tree reference, parent reference(s), author information, and a message. File contents are stored as objects called blobs; trees associate names and modes with those objects. You do not need to edit those internal objects manually.
Create a repository you can safely experiment in
Inside Linux, choose a new empty directory. mktemp avoids accidentally initializing your existing work project:
study_git=$(mktemp -d)
cd "$study_git"
git init
pwd
Record the printed path for the next bites. Configure an author locally, replacing the example values with the identity you intend to use. These settings apply to this repository only; they do not authenticate you to a remote server.
git config user.name 'Your Name'
git config user.email '[email protected]'
printf '# Lab runbook\n' > runbook.md
git status --short
git add runbook.md
git diff --cached
git commit -m 'Start lab runbook'
git log --oneline -1
Before git add, short status should show ?? runbook.md: an untracked file. After staging, it should show A runbook.md. The commit captures the staged contents and produces a commit ID; your ID will differ because metadata and time differ. HEAD normally identifies your current branch, which points to your latest commit.
See why staging is a separate step
printf '\nRecord observations before changes.\n' >> runbook.md
git diff
git status --short
git add runbook.md
printf '\nCheck the exact service name.\n' >> runbook.md
git status --short
git diff --cached
git diff
The final short status should show MM runbook.md. The first column describes the index relative to the commit; the second describes the working tree relative to the index. The observations line is staged, while the service-name line is still only in the working tree. Committing now would omit that second line.
Compare the two diffs before completing the change:
git add runbook.md
git diff --cached
git commit -m 'Explain checks before a change'
git status --short
git show HEAD:runbook.md
A clean short status prints nothing. git show HEAD:runbook.md reads the version in the commit, independent of later edits. A useful commit captures one understandable intent with a message that tells a reader what changed.
Decide what belongs in history
Keep source, runbooks, and appropriate dependency lock files. Keep passwords, private keys, local environment secrets, caches, and generated state out. .gitignore tells Git which untracked paths to ignore normally; adding a tracked file to it does not untrack the file or erase earlier commits. If a secret was committed, deleting its latest line does not revoke it. Revoke or rotate the exposed credential, then follow the repository’s incident and history-cleanup process.
Check yourself: you staged a file and then fixed a typo; which version will commit? The staged version until you stage the correction. Does a clean status mean the program works? No. It only says the tracked file versions agree and no reportable untracked changes remain. Keep this repository, with clean status, for the branches bite.
Sources
Primary references: Git recording changes↗; Git diff↗.
Your notes and evidence
Record observations, questions, or links to your work. Keep credentials out of your notes.
Back up or restore this path
Progress and notes stay in this browser. A backup contains only this learning path.