Video in progress
You made a mistake in the last commit message, or forgot to add a file. How do you fix it?
git commit --amend replaces the last commit with a new one: you can change the message or add the new files from staging. It is safe to use only if the commit has not been pushed yet.
📖 Answer
# the message only
git commit --amend -m "Kurs narxi chegirmadan keyin yaxlitlanadi"
# add a forgotten file, the message stays the same
git add CoursePriceTest.java
git commit --amend --no-edit
--amend does not edit the old commit. It creates a new commit with a new hash, and the old one drops out of the history. So if the commit is already on the server and others have pulled it, you can send the amended version only with a force push, and that breaks your colleagues' history.
On your own personal feature branch, while the PR is still in review, amend + --force-with-lease is considered normal in many teams.
Sign up to mark studied questions and save your progress.