How can you add a message to a commit?
Posted by HenryPk
Last Updated: June 30, 2024
In Git, you can add a message to a commit using the -m option with the git commit command. Here's how to do it: 1. Stage your changes (if you haven't done so already): Use git add to stage the files you want to commit. For example:
git add filename.txt
Or to stage all changes:
git add .
2. Commit with a message: Once your changes are staged, you can commit them with a message using:
git commit -m "Your commit message here"
Example
If you want to commit changes with the message "Fix bug in feature X", you would run:
git commit -m "Fix bug in feature X"
Additional Option
If you want to write a more detailed commit message, you can omit the -m flag, and it will open your default text editor where you can write a multi-line commit message. To do this, you would run:
git commit
This will allow you to provide a subject line followed by a blank line and then your detailed message.
Amending Last Commit Message
If you need to modify the message of the most recent commit (without changing its content), you can use:
git commit --amend -m "New commit message"
Summary
- Use git commit -m "message" for simple one-line messages. - Use git commit for multi-line messages. - Use git commit --amend to change the last commit message.
Related Content