GIT & VERSION CONTROL · REFERENCE
Understanding History
Read recorded versions, compare changes, and label milestones without altering your current files.
At a glance
| Term or command | What it means | When to use it |
|---|---|---|
| git log --oneline | Lists commits with short IDs and messages. | Scan recent history. |
| git show HEAD | Shows the current commit and its patch. | Inspect what the latest commit introduced. |
| HEAD | Usually identifies the commit at the tip of the current branch. | Use when referring to the current checked-out version. |
| HEAD~1 | The first parent of the current commit. | Compare the most recent change in a simple linear history. |
| git diff A B | Compares two recorded versions. | See what differs between chosen commits. |
| git tag | A named reference to a particular version. | Label a release milestone. |
Commands are examples, not an interactive terminal. Run them in your own learning repository after checking the prerequisites. Output, paths, commit IDs, and wording can vary. Host-specific instructions are labeled.
Read the story so far
After the two commits in Start Here, run inside my-website. The IDs below are illustrative.
Commands
git log --oneline
Example output
b2c3d4e Update homepage heading
a1b2c3d Create first webpage
The first entry is newest. These are two snapshots of the same project, not two separately saved website folders. If the log opens a pager, press q to exit.
Inspect one version’s change
This example requires at least two commits. Neither command changes your files.
Commands
git show HEAD -- index.html
git diff HEAD~1 HEAD -- index.html
Example output
- <h1>My first version</h1>
+ <h1>My updated website</h1>
The output is an excerpt. The double dash separates revision arguments from the filename. With merges, “previous commit” can be ambiguous; HEAD~1 specifically follows the first parent.
Read the branch shape
git log --oneline --graph --all
Graph draws lines showing parent relationships; --all includes other references such as branches. Branch lines help explain which changes were developed separately and later combined. Commit timestamps alone are not the whole history structure.
Label a milestone
After reviewing the current version, create an annotated local tag. The -a flag makes an annotated tag; -m gives its message.
git tag -a v1.0 -m "First complete website"
git show v1.0
A tag is a stable name for a selected version, while a branch advances as work continues. Tags are not automatically sent by an ordinary branch push. Push a chosen tag explicitly when you want to share it.
git push origin v1.0
Sources and further reading
Study questions
Explain it in your own words, then open the answer.
Does git log change my files?
No. It displays history.
Why do my commit IDs differ from the examples?
IDs depend on commit content and metadata; the guide’s IDs are illustrations.
What does HEAD~1 mean?
The first parent of the current commit.
How do I exit a history pager?
Press q.
Is a tag automatically uploaded with every branch push?
No. Push the selected tag explicitly when needed.