Amending
Amending is the process of updating the most recent commit with new
changes. This is useful when you forgot to include a file or a change, or made a
mistake in the commit message. Amending creates a new commit with the
updated changes, replacing the previous commit.
Use Cases:
- Fixing typos in commit messages
- Adding files you forgot to include in the last commit
- Updating the most recent commit with new changes
Examples:
Fixing a typo in the last commit message:
git commit --amend -m "New commit message"
Adding/updating specific files in the last commit:
# Add the file(s) to the staging area
git add [filename]
# Amend to the previous commit without editing the commit message
git commit --amend --no-edit
git add [filename]
# Amend to the previous commit without editing the commit message
git commit --amend --no-edit