Edit the Last Commit
You have just committed some changes to your Git repository, but you realize that you forgot to include a file or make a small change. You don't want to create a new commit just for this small change, but you also don't want to change the commit message. How can you edit the last commit without changing its message?
Tasks
To demonstrate how to edit the last commit, let's use the repository from https://github.com/labex-labs/git-playground
.
- Navigate to the repository directory and configure your GitHub identity.
- Realize that you forgot to include a file or make a small change. Add the text "New content" to the end of the
README.md
file. Add any staged changes to the last commit, without changing its message.
- Verify that the last commit now includes the changes you made.
This is the content of the late commit: