All posts

Which Git hook stopped my commit?

Find the hook that rejected a commit, read its output and test a corrected message in MoonGit.

If Git stops a commit because a hook failed, start with the hook name and the message it printed. In MoonGit 1.0.13, the commit composer shows both when Git reports a hook failure and Git hooks is enabled. Keep your staged changes in place while you check what the hook expects.

Read the hook that failed

Imagine a repository requires a ticket number at the start of each commit message. You stage a fix and try to commit with Fix login. The composer reports that commit-msg stopped the commit, and the hook says to start the subject with a ticket such as APP-42: . In this case, the message is the part you need to fix.

MoonGit's commit composer shows the commit-msg hook failure, exit code 1 and the ticket-prefix hint
Read the hook name and its output, then choose Open Git Hooks to inspect the result. Open full-size image

commit-msg gets a file containing the proposed message. A pre-commit hook runs earlier and might check staged files or run a formatter instead. The name in the composer tells you where to start, and the output tells you what the repository's check found. Git's hook reference

Test the corrected message

Choose Open Git Hooks from the failure in the composer. MoonGit selects the hook and opens the run pane with the result from the stopped commit. For this example, put APP-42: Fix login in Sample message and choose Run hook. The example check reports that the ticket prefix is valid and exits with code 0.

The test runs the saved hook with your sample input. Your commit message in the composer is separate. Go back to the composer, change the actual subject to APP-42: Fix login and commit. Check the graph for the new commit.

Try it in a practice repository

Use a disposable Git repository to install the same ticket check and see the failed and passing results yourself. The guide shows how to enable Git hooks, create the script, and run both messages. Write and test a Git hook in MoonGit

More posts