Add a Commit Message Template
Without a commit message template, developers may be tempted to write vague or uninformative commit messages, such as "fixed bug" or "updated code". This makes it difficult for others to understand the purpose of the change and can lead to confusion or mistakes down the line. By setting up a commit message template, developers are encouraged to provide more detailed and informative commit messages, which can improve collaboration and productivity.
Tasks
For this challenge, let's use the repository from https://github.com/labex-labs/git-playground
.
- Navigate to the repository directory and configure your GitHub identity.
- Create a new file called
commit-template
in the current directory of the repository.
- Open the
commit-template
file in a text editor and add the following lines:
## <type>: <subject>
## <body>
## <footer>
## This creates a template with three sections:
## "<type>" indicates the type of submission, such as "feat" or "fix"
## "<subject>" is a short #summary describing the content of the submission
## "<body>" is a more detailed description
## "<footer>" can contain other metadata, such as the #associated issue number or other comments.
- Press Esc and enter the :wq command, then press Enter to save your changes and exit the
commit-template
file editor.
- Add
commit-template
files to the staging area.
- Set the
commit-template
file as the commit message template for the repository.
- Open the commit message editor and notice that the commit message editor now contains the commit message template you created in step 3.
- Press Esc and enter the :q command, then press Enter to exit the commit message editor.