Editing Commit Messages Deeper in History

Commit 4 of 6 has the wrong ticket number. Fix it without touching anything else — except every hash after it.

A real, small correction: the "Add dinner recipe" commit, sitting 4 commits deep in this branch's real history, needs a ticket reference added to its message. Its actual content is completely fine — only the message needs to change.\n\nreword pauses the rebase to let exactly that message be rewritten, then continues replaying everything after it. This is where the real, sometimes-surprising truth about git history becomes unavoidable: changing ANY commit — even just its message — genuinely changes its hash, and every commit built on top of it inherits a new parent, so it too gets a genuinely new hash. Content unchanged; hashes, changed all the way to the tip.

A Real Message, Needing a Small Correction

git log --oneline -6

The real commit that needs its message fixed sits several commits back — its content stays exactly as it is.

Rewording It, Scripted

GIT_SEQUENCE_EDITOR="sed -i '4s/^pick/reword/'" \
GIT_EDITOR="sed -i '1s/.*/Add dinner recipe (RECIPE-204)/'" \
git rebase -i HEAD~6

Exactly the same real scripting technique from Lesson 3.1.1 — reword marks the commit, GIT_EDITOR supplies the new real message.

The Real, Unavoidable Consequence

git log --oneline -6

Every commit after the reworded one now shows a genuinely different hash — their real content is completely unchanged, but their parent isn't, and a commit's hash always depends on its parent.

reword (in an interactive rebase)

Pauses the rebase to let exactly one real commit's message be rewritten, leaving its actual content completely untouched. Confirmed directly in this lab: the file diff of the reworded commit is byte-for-byte identical before and after.

Hash propagation

A commit's hash is computed from its content AND its parent's hash — change either, and the hash changes. Confirmed directly in this lab: rewording one commit's message alone was enough to give every later commit in the branch a genuinely new hash.

🔍 Find the Real Commit Needing Correction

Four commits deep, the dinner recipe commit is missing its real ticket reference.

cd ~/team-recipes && git log --oneline -6

student@lab:~$ cd ~/team-recipes && git log --oneline -6 6aae69c (HEAD -> feature/meal-recipes) Add dessert recipe a842266 Add snack recipe ec9fdc2 Fix typo in breakfast recipe 58cb5b5 Add dinner recipe 6219392 Add lunch recipe 0f90512 Add breakfast recipe

📝 Reword It, Scripted

Fix exactly this one message, without touching its actual content.

cd ~/team-recipes && GIT_SEQUENCE_EDITOR="sed -i '4s/^pick/reword/'" GIT_EDITOR="sed -i '1s/.*/Add dinner recipe (RECIPE-204)/'" git rebase -i HEAD~6

student@lab:~$ cd ~/team-recipes && GIT_SEQUENCE_EDITOR="sed -i '4s/^pick/reword/'" GIT_EDITOR="sed -i '1s/.*/Add dinner recipe (RECIPE-204)/'" git rebase -i HEAD~6 [detached HEAD b50e6c6] Add dinner recipe (RECIPE-204) Date: Thu Aug 27 20:14:06 2026 +0200 1 file changed, 1 insertion(+), 1 deletion(-) Successfully rebased and updated refs/heads/feature/meal-recipes.

🔎 Confirm the Real, Unavoidable Hash Change

Everything after the reworded commit now has a genuinely new hash.

cd ~/team-recipes && git log --oneline -6

student@lab:~$ cd ~/team-recipes && git log --oneline -6 c5b0f12 (HEAD -> feature/meal-recipes) Add dessert recipe 570da3e Add snack recipe b50e6c6 Add dinner recipe (RECIPE-204) 58cb5b5 Add dinner recipe 6219392 Add lunch recipe 0f90512 Add breakfast recipe

Lab 3.1.3 complete. A real commit message, fixed deep in history — and every commit after it, genuinely rehashed:\n\n\n Commit found : ✅ 4 deep, content fine\n Reworded, scripted : ✅ real ticket reference added\n Hash propagation seen : ✅ 2 commits genuinely rehashed\n

Enable JavaScript to run the live terminal and track your progress.