Git commit amend¶
Git commit amend is a command-line operation used to modify the most recent commit in a repository's history.^[600-developer-tools-git-git-command.md]
Functionality¶
The git commit --amend command allows developers to incorporate staged changes into the previous commit or alter the commit message without creating a new commit ID^[600-developer-tools-git-git-command.md].
This tool is useful for correcting mistakes immediately after a commit, such as adding a forgotten file or fixing a typo in the commit message^[600-developer-tools-git-git-command.md].
Common Use Cases¶
- Modifying the commit message:
Running
git commit --amendopens the editor to change the message of the last commit^[600-developer-tools-git-git-command.md]. - Adding files to the previous commit:
Running
git commit --amend <file1> <file2>adds the specified files to the last commit^[600-developer-tools-git-git-command.md].
Related Concepts¶
- Git reset
- Git stash
- Git rebase
- [[Git branch]]
Sources¶
^[600-developer-tools-git-git-command.md]