Lesson 16 · Everyday work
Correct a local commit message or content
Correct a typo and message in one private hero commit while retaining its old tip. Learn why amend replaces identity and why unrelated staged content must stay out.
- Level: Intermediate
- 8 min read
- 5 min video
- Updated
- Before this lesson: Ignore files and clean untracked work safely
Progress saved in this browser.
Playing loads the video from YouTube (privacy-enhanced mode).
What you will learn
- Inspect the commit being replaced.
- Separate amended contents from message-only editing.
- Preserve the old committed tip.
- Verify new identity and unchanged parent.
Before you start
Start from a separate copy of lesson 15's result, on a branch scenario/amend. The full HEADING_DRAFT page is committed as fix: hedaing; the work tree is clean and the commit is unpublished. rescue/before-amend names that exact draft tip.
The video was recorded with Git 2.52.0 and GitTree 2.0 on Ubuntu 24.04: the correction, the amend and the message-only edit were done in the app; the draft, its rescue branch and the checks ran in the terminal. Nothing was run on macOS or Windows, and Ubuntu is the only Linux system recorded. GitTree's source Git floor is 2.39.0.
GitTree asks you to sign in; the Free plan then covers every step here. No provider account, Pro/trial, API credential or internet service is needed. A local bare origin is not GitLab or CI. All identities use example.com; never run this lesson inside a source checkout.
Make mutations through either GitTree or the native path at identical inputs, not both consecutively. Read-only verification can follow either. Any preparation described as terminal work is labeled native preparation, never an invented app feature.
Concept and state effects
Amend writes a replacement for the last commit from the current index. It is not appending a tiny correction record to the old commit. Content and message can change together, while the old object may remain reachable through the rescue ref.
Message-only editing should not silently include unrelated staged changes. The app's Edit Commit Message… route rewrites the selected commit/descendants; it differs from the composer Amend Previous Commit path demonstrated here.
Here the changed subject guarantees a different object identity. Same parent does not mean same commit. Do not teach amend as a harmless edit of a published commit others already based work on.
New index content becomes replacement commit; scenario branch/HEAD move old C→C′, parent stays M, work/index clean. Rescue remains C; original main/server unchanged.
Prepare the exact project state
Begin from a separate ordinary copy of the clean project as lesson 15 left it. The original gittree-features stays preserved; do not run this scenario in the original or a source checkout. (An earlier plan of the course started this lesson from a later merge lesson's result; that lesson is not recorded yet, so the video uses lesson 15's project and the same steps.) The two page bodies below are the project's index.html with only the hero heading changed. Repo-local demo signing is off and GitTree Demo <demo@example.com> is the identity.
Complete file inputs
Save only at the phase named below. These are full UTF-8/LF bodies with a final newline; never paste Markdown fences. Unchanged runnable files inherit the named input. Versions in separate variants must not overwrite the original.
index.html — HEADING_DRAFT
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>GitTree Features — course demo</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header class="site-header">
<a href="#main">GitTree Features</a>
</header>
<main id="main">
<section class="hero" aria-labelledby="hero-title">
<p class="eyebrow">GitTree Learn demo project</p>
<h1 id="hero-title">See your work cleary.</h1>
<p id="hero-copy">Choose one change, then check what Git saved.</p>
</section>
<section class="features" aria-labelledby="features-title">
<h2 id="features-title">Follow your work</h2>
<div class="cards">
<article class="feature-card">
<h3>History</h3>
<p>Read commits and branches together.</p>
</article>
<article class="feature-card">
<h3>Changes</h3>
<p>Review the exact content selected for a commit.</p>
</article>
<article class="feature-card">
<h3>Recovery</h3>
<p>Inspect the scope of a recovery point before using it.</p>
</article>
</div>
</section>
</main>
<footer><p>Built by a fictional team for GitTree Learn. Review one change at a time.</p></footer>
<script type="module" src="site.js"></script>
</body>
</html>index.html — HEADING_FIXED
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>GitTree Features — course demo</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header class="site-header">
<a href="#main">GitTree Features</a>
</header>
<main id="main">
<section class="hero" aria-labelledby="hero-title">
<p class="eyebrow">GitTree Learn demo project</p>
<h1 id="hero-title">See your work clearly, one change at a time.</h1>
<p id="hero-copy">Choose one change, then check what Git saved.</p>
</section>
<section class="features" aria-labelledby="features-title">
<h2 id="features-title">Follow your work</h2>
<div class="cards">
<article class="feature-card">
<h3>History</h3>
<p>Read commits and branches together.</p>
</article>
<article class="feature-card">
<h3>Changes</h3>
<p>Review the exact content selected for a commit.</p>
</article>
<article class="feature-card">
<h3>Recovery</h3>
<p>Inspect the scope of a recovery point before using it.</p>
</article>
</div>
</section>
</main>
<footer><p>Built by a fictional team for GitTree Learn. Review one change at a time.</p></footer>
<script type="module" src="site.js"></script>
</body>
</html>In GitTree
Palette: Command+Shift+P (Ctrl+Shift+P on Ubuntu); type the exact named command and select it. Named-ref actions use that row's context menu, not an argument-free palette shortcut.
- Prepare the private draft and rescue branch as below; confirm no remote contains the draft.
- Show Files → index.html; save full HEADING_FIXED, preserving all other page content.
- Show Working Changes; inspect only the intended heading replacement and Stage File index.html.
- In the composer check Amend Previous Commit; inspect the actual last commit being replaced, not an older graph selection. (In this build the Summary field is not filled in with the old message; you write the new one in the next step.)
- Set Summary fix: clarify the hero heading. Keep push/signoff/hooks bypass and other optional behaviors off; review staged contents.
- Submit once with Command+Enter (Ctrl+Enter on Ubuntu) from the composer; wait for the actual completion. Do not submit a second ordinary commit. The Amend Previous Commit option turns itself off afterwards.
- Verify actual C′ differs from rescue C, same parent, full HEADING_FIXED and clean work. Turn Amend Previous Commit off before later ordinary work.
- Message-only alternative, in a separate copy that still has the draft: right-click the draft commit → Edit History → Edit Commit Message…. The dialog is titled “Edit Message of” the commit's short id and says that the commit and every commit above it get new ids. Replace the Message with the exact corrected subject and choose Save Message. The tree and the parent stay the same; only the id and the message change. Do not repeat this on the amended result.
For every ordinary commit: Summary is the stated subject; Description empty; Amend Previous Commit, Skip Hooks, Add Signed-off-by, Different Author, Push After Commit and Allow Empty Commit off; no co-authors. Stage only the named files, then Commit Changes to N Files once (File for one), or Command+Enter as an alternative. Wait for the real result. A lesson that explicitly amends changes only that stated option.
In the terminal
In the separate copy of lesson 15's result:
git switch --create scenario/amendPut HEADING_DRAFT over index.html (the video saved the lesson's file in ~/Downloads and uses cp ~/Downloads/HEADING_DRAFT.html index.html), then:
git add -- index.html
git commit --quiet -m "fix: hedaing"
git branch rescue/before-amendSave full HEADING_FIXED, then:
git add -- index.html
git commit --quiet --amend --message "fix: clarify the hero heading"
git log -1 --format=%s
git rev-parse HEAD rescue/before-amend HEAD^ rescue/before-amend^
git status --shortObserved subject:
fix: clarify the hero headingThe first two SHA outputs differ; the last two agree. Full recorded file equals HEADING_FIXED, work clean. Native message-only alternative in a separate clean draft copy uses git commit --amend --only -m "fix: clarify the hero heading"; --only avoids including unrelated staged paths for that message-only task. The app's graph reword operation is a distinct source-backed route; verify it in the installed build.
Result
Where you end: Replacement commit says fix: clarify the hero heading and contains full HEADING_FIXED; parent matches old commit's parent, ID differs; old tip rescued; clean, unpublished.
Common mistakes
- Amending with unrelated staged files.
- Treating the alternative pane as the original checkpoint.
- Repeating a completed mutation after app success.
If something goes wrong
The rescue branch names the old committed draft. Compare before choosing a restoration; it does not preserve arbitrary unstaged edits. If hooks/signing fail, inspect the real output, do not bypass them to match the lesson.
Check your understanding
Answer each question, then read why. Questions marked “Required” count toward completing the lesson.
0 of 6 correct
Answer the required questions correctly to complete the lesson.
Checked in this browser.
Practice
Prove same parent, changed object ID, exact corrected heading/message and clean state. Predict how an extra staged file changes composer amend content in a separate replay.
Your own confirmation: the site cannot see your computer.
To complete the lesson, answer the required questions correctly and confirm the practical exercise.
Recap
- Amend creates a replacement.
- The index controls amended content.
- Message-only is a separate scope.
Related
Glossary terms introduced
Amend — تعديل الإيداع الأخير; reword — إعادة صياغة; replacement commit — إيداع بديل.
Video transcript
The narration of the video, cue by cue.
Show the transcript
- Start from the exact checkpoint.
- Name the branch, index and working version.
- Prepare only the isolated course copy.
- Protect the private draft before replacing it.
- Save the complete intended correction.
- Review the index, not only the message.
- Amend replaces the actual last commit.
- Write the corrected subject explicitly.
- Submit the replacement only once.
- Same parent does not mean same identity.
- Message-only editing has a separate scope.
- What does amend create?
- Git objects are immutable; replacement gets a new ID.
- What must be reviewed?
- Composer amend uses the index and last commit context.
- Parent of corrected C′?
- The replacement occupies the same ancestry position.
- Add an unrelated staged file before amend: content?
- The current index defines the replacement tree.
- Draft was published: proceed as private?
- Published identity may be used by others.
- Which evidence is required?
- Verify both replacement identity and intended content.
- Verify the actual result, not just a message.
- Predict the changed input before acting.
- Preserve useful work before recovery.
- Prove the checkpoint before continuing.
- Keep the verified result for the next step.