MicrolearnENPTES

Fix the last commit: --amend

Lesson 21 of 24 · Git.Micro

Typo in the message, or a file left out? git commit --amend replaces the last commit with a corrected one.

Stage what was missing, then git commit --amend -m "new message" (or --no-edit to keep the message).

Amend doesn't edit the old commit: it creates a new one with a new hash, in its place.

Only amend commits you haven't pushed: others may already have the old one.

After git commit --amend, the commit's hash…

Your last commit has a typo in its message and forgot contact.css. Fix both with a single amend: the message must be Add contact page, with no extra commit.

No extra commit: the old one was replaced

No “Add contcat page” commit left in the history

Do it in the browser: a real Git tool, a short mission and instant feedback. No install.

Start this lesson — free
← Feature branches and pull requestsreset: move a branch back →

All lessons · Git.Micro