Web Development Pro | Lesson 051 | Version Control and Reviewable Changes
Web Development Pro · Lesson 51 of 60
Module 6: Delivery and the capstone
In this lesson
Prerequisites and learning outcomes
Complete lesson 50 first. This lesson builds on git concepts, small commits, and rollback. By the end, you can read a diff and prepare a small reviewable change in a disposable repository. Plan 10–15 minutes for the core explanation and additional time for the worked practice.
Make a change understandable before saving it
Version control records snapshots and the relationships between them. It helps you inspect what changed, explain why, and return to an earlier state when appropriate. It does not automatically test a website or publish it. A local commit can exist entirely on your own machine with no remote service involved.
For this lesson, use only a new disposable practice repository. Do not run the commands inside an important existing project. The supplied Python exercise creates a temporary child folder, initializes Git there, uses an explicitly fictional local author identity, performs the demonstration, and removes only that temporary folder when finished. It never adds a remote or makes a network request.
Distinguish the three useful views
The working tree contains the files you are editing. The staging area selects the content intended for the next commit. A commit records the staged snapshot with a message and history information. These are related but not interchangeable. Editing a file after staging it does not automatically replace the already staged version.
Use git status to see which files are untracked, modified, or staged. Use git diff to inspect unstaged changes and git diff --staged to inspect what the next commit would contain. Before committing, review both the file list and the actual content. A filename alone cannot reveal an accidental secret or unrelated change.
git status --short
git diff
git add index.html
git diff --staged
git commit -m "Clarify the fictional workshop heading"
These commands belong in the disposable repository after its initial setup. Staging the named file is more deliberate than staging everything without inspection. A real project may use a different workflow, but the principle remains: know exactly which changes the snapshot records.
Keep commits focused on a reason
A useful commit answers one coherent question. “Clarify the workshop heading” can include the heading change and its directly related test adjustment. Combining that with an unrelated stylesheet reorganization makes review and reversal harder. Small does not mean one line; it means the change has an understandable purpose.
Write a message explaining the effect rather than merely saying “updates.” When the reason is not obvious from the diff, add it to the description. A future maintainer should understand the requirement without reconstructing your entire debugging session. Avoid putting private information or credentials in commit messages.
Review the diff as if you had not written it. Check deletions as carefully as additions. A replaced paragraph may accidentally remove the fictional-demo disclaimer or access information. Run the relevant tests against the staged intent, and ensure the working tree does not contain a different untested version of the same file.
Understand branches without needing a remote
A branch is a movable name for a line of development. Creating a local branch does not create a cloud copy or share code with another person. A repository can have several branches while remaining entirely offline. Remote operations are separate and are outside this exercise's scope.
A clean working tree reduces surprises when switching between lines of work. Do not use destructive commands to force a switch when you do not understand the current changes. First inspect and preserve the work you need. This beginner exercise avoids history rewriting and shared branches altogether.
A commit is not a backup strategy by itself. If the only repository is on one damaged disk, its history may be lost too. Backups and authorized remote storage are separate operational choices. Do not infer permission to upload a project merely because version control would benefit from another copy.
Reverse an ordinary change with a new commit
The demonstration makes an initial snapshot, changes “Workshop demo” to “Learning hub demo,” commits it, and then reverts that second commit. git revert creates a new commit that applies an inverse change. The history retains both the original change and the later reversal, which makes the sequence reviewable.
Reverting is different from deleting history. It can still conflict if later changes overlap the same lines. In a real project, inspect the result and rerun affected checks rather than assuming the inverse patch restores every external effect. Reverting source code does not automatically undo data migrations, emails, or other actions performed by a running service.
The sample uses git revert --no-edit HEAD only after verifying the intended latest commit in its isolated repository. Do not copy that command into an unrelated repository without checking what HEAD actually names. The safe scope of the exercise comes from the disposable setup, not from the command being universally harmless.
Keep generated and sensitive material deliberate
A .gitignore file can tell Git to ignore matching untracked files. It does not retroactively remove secrets from existing commits and does not make tracked files private. Review files before their first commit. For a simple static site, decide whether generated bundles belong in history based on the project's documented delivery process.
Do not commit real attendee information, local credentials, or unnecessary machine-specific settings to this learning repository. Use fictional data already intended for the exercise. A clean diff is easier to review when temporary logs and large accidental artifacts are excluded from the intended snapshot.
The supplied local test verifies that three commits exist after the reversal, the final file matches the original text, the working tree is clean, and no remote is configured. Those checks demonstrate Git mechanics only. They do not establish that a real website was reviewed, deployed, or rolled back on a host.
Worked practice
Worked exercise 1: Notice two versions of one file
Task: You stage a heading change, then edit the heading again. Worked answer: inspect git diff and git diff --staged separately. The working tree and staged snapshot now differ. Stage the intended final content only after reviewing it, then test the version you mean to record.
Worked exercise 2: Split unrelated work
Task: One diff changes search behavior and reorders every stylesheet rule. Worked answer: separate the unrelated refactor from the behavior fix where practical. Each change then has a clearer reason, a smaller review surface, and a more understandable reversal path.
Worked exercise 3: Explain a revert
Task: A teammate thinks reverting removes the original commit. Worked answer: an ordinary git revert adds a new inverse commit while retaining history. Inspect and test its result, especially if later changes overlap; it does not undo outside effects automatically.
Knowledge check
Question 1
What does git diff --staged show? A) The changes selected for the next commit. B) All working-tree changes, including those not staged. C) The contents of the most recent commit without comparison. D) Only edits made after the last staging operation.
Check question 1: answer and explanation
Answer: A. The staging area is distinct from unstaged working-tree edits.
Question 2
What happens when a staged file is edited again? A) The most recent commit immediately records the new edit. B) The new edit always replaces the staged content. C) The working tree may differ from the staged snapshot. D) The new edit is discarded because the file is already staged.
Check question 2: answer and explanation
Answer: C. Staging selects content at the time of the add operation.
Question 3
Why prefer a focused commit? A) It guarantees all tests pass. B) It makes the reason, review, and possible reversal clearer. C) It removes the need for a diff. D) It prevents later conflicts entirely.
Check question 3: answer and explanation
Answer: B. Coherent scope supports human review without guaranteeing correctness.
Question 4
What does an ordinary revert do? A) Removes every copy of a change. B) Reverses all external service effects. C) Deletes the branch's history. D) Records an inverse change in a new commit.
Check question 4: answer and explanation
Answer: D. History remains visible and the resulting content still needs checking.
Question 5
What does .gitignore do for an already committed secret? A) It removes the value from older snapshots on the next commit. B) It does not remove that secret from history. C) It stops the tracked file from appearing in future diffs automatically. D) It removes the value from every existing clone.
Check question 5: answer and explanation
Answer: B. Ignoring future untracked matches does not repair past exposure.