gitpractice.dev

brewly — Ch.4 · Fix the commit you just made

Exercise 1 of 9

Before you start

Replacing the last commit

git commit --amend makes a new commit that replaces the last one. It takes whatever is staged now, plus everything the old commit had.

Without more options git opens the editor with the old message. -m gives a new message instead, and --no-edit keeps the old one.

The replaced commit gets a new id. Only amend commits you have not pushed yet.

git status
what was left out of the commit?
git add <file>
stage it
git commit --amend
replace the last commit and edit its message
git commit --amend -m "New message"
replace it with a new message
git commit --amend --no-edit
replace it, keeping the message
git log --oneline
check the result
You can reopen this any time with “Lesson”.

Continue on a desktop

Typing git on a small screen is no fun. Open this page on a laptop or desktop to practise.

Back to the path