0
0
Gitdevops~5 mins

commit-msg hook for message validation in Git - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a commit-msg hook in Git?
A commit-msg hook is a script that runs automatically after a commit message is entered but before the commit is finalized. It checks the commit message to ensure it meets certain rules or formats.
Click to reveal answer
beginner
Where do you place a commit-msg hook script in a Git repository?
You place the commit-msg hook script inside the .git/hooks/ directory of your repository, and it must be executable.
Click to reveal answer
intermediate
What happens if a commit-msg hook script exits with a non-zero status?
If the commit-msg hook script exits with a non-zero status, Git stops the commit process and shows an error message. This prevents the commit from being saved.
Click to reveal answer
beginner
Give an example of a simple rule a commit-msg hook might enforce.
A simple rule could be that the commit message must start with a capital letter and be at least 10 characters long.
Click to reveal answer
beginner
How can you test a commit-msg hook script?
You can test it by trying to make a commit with different messages and seeing if the hook allows or blocks the commit based on your rules.
Click to reveal answer
Where is the commit-msg hook script located in a Git repository?
A.git/hooks/
B.git/commit-msg/
Croot directory
Dany directory
What does a non-zero exit code from a commit-msg hook script do?
AAutomatically fixes the commit message
BAllows the commit to proceed
CDeletes the commit message
DStops the commit and shows an error
Which of these is a valid use of a commit-msg hook?
ARun unit tests
BCheck commit message format
CPush to remote repository
DMerge branches
How do you make a commit-msg hook script executable?
ANo action needed
BRename it to <code>commit-msg.sh</code>
CRun <code>chmod +x .git/hooks/commit-msg</code>
DPlace it in the root directory
What file does the commit-msg hook receive as input?
AThe file containing the commit message
BThe staged files
CThe repository config file
DThe last commit hash
Explain how a commit-msg hook can help maintain commit message quality.
Think about how automatic checks can stop bad messages.
You got /4 concepts.
    Describe the steps to create and enable a commit-msg hook for message validation.
    Focus on script location, permissions, and testing.
    You got /4 concepts.