You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>This feature checks whether a string or a range of git commits follows the given committing rules. Comments in git messages will be ignored.</p>
2371
2503
<p>To set up an automatic check before every git commit, please refer to <ahref="../../tutorials/auto_check/">Automatically check message before commit</a>.</p>
<h3id="use-cz-check-to-validate-a-commit-message-before-committing">Use <code>cz check</code> to validate a commit message before committing<aclass="headerlink" href="#use-cz-check-to-validate-a-commit-message-before-committing" title="Permanent link">¶</a></h3>
2381
2513
<h4id="option-1-use-message-to-check-a-given-string">Option 1: use <code>--message</code> to check a given string:<aclass="headerlink" href="#option-1-use-message-to-check-a-given-string" title="Permanent link">¶</a></h4>
<h4id="option-3-use-commit-msg-file-to-read-the-commit-message-from-a-file">Option 3: use <code>--commit-msg-file</code> to read the commit message from a file<aclass="headerlink" href="#option-3-use-commit-msg-file-to-read-the-commit-message-from-a-file" title="Permanent link">¶</a></h4>
<p>For more information on <code>REV_RANGE</code>, check the <ahref="https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection#_commit_ranges">git documentation</a>.</p>
<p>Validate all git commit messages starting from when you first implemented commit message linting:</p>
2425
2557
<p><strong>(Why this is useful?)</strong> Let's say you decided to enforce commit message today. However, it is impractical to <code>git rebase</code> all your previous commits. <code>--rev-range</code> helps you skip commits before you first implemented commit message linting by using a specific commit hash.</p>
<p>This can be useful when cooperating with git hooks. Please check <ahref="../../tutorials/auto_check/">Automatically check message before commit</a> for more detailed examples.</p>
<p>Empty commit messages typically instruct Git to abort a commit, so you can pass <code>--allow-abort</code> to
2450
2583
permit them. Since <code>git commit</code> accepts the <code>--allow-empty-message</code> flag (primarily for wrapper scripts), you may wish to disallow such commits in CI. <code>--allow-abort</code> may be used in conjunction with any of the other options.</p>
<divclass="highlight"><pre><span></span><code><spanclass="c1"># The following message passes the check because it starts with 'Merge'</span>
2466
-
cz<spanclass="w"></span>check<spanclass="w"></span>--message<spanclass="w"></span><spanclass="s2">"Merge branch 'main' into feature/new-feature"</span><spanclass="w"></span>--allowed-prefixes<spanclass="w"></span><spanclass="s1">'Merge'</span>
2467
-
2468
-
<spanclass="c1"># The following fails</span>
2469
-
cz<spanclass="w"></span>check<spanclass="w"></span>--message<spanclass="w"></span><spanclass="s2">"Merge branch 'main' into feature/new-feature"</span><spanclass="w"></span>--allowed-prefixes<spanclass="w"></span><spanclass="s1">'aaa'</span>
2470
-
</code></pre></div>
2598
+
<p>```bash</p>
2599
+
<h1id="the-following-message-passes-the-check-because-it-starts-with-merge">The following message passes the check because it starts with 'Merge'<aclass="headerlink" href="#the-following-message-passes-the-check-because-it-starts-with-merge" title="Permanent link">¶</a></h1>
2600
+
<p>cz check --message "Merge branch 'main' into feature/new-feature" --allowed-prefixes 'Merge'</p>
2601
+
<h1id="the-following-fails">The following fails<aclass="headerlink" href="#the-following-fails" title="Permanent link">¶</a></h1>
2602
+
<p>cz check--message "Merge branch 'main' into feature/new-feature" --allowed-prefixes 'aaa'
cz<spanclass="w"></span>check<spanclass="w"></span>--message<spanclass="w"></span><spanclass="s2">"docs:very long long long long message with many words"</span><spanclass="w"></span>-l<spanclass="w"></span><spanclass="m">3</span>
2478
-
</code></pre></div>
2606
+
<p>```bash</p>
2607
+
<h1id="the-following-passes">The following passes<aclass="headerlink" href="#the-following-passes" title="Permanent link">¶</a></h1>
0 commit comments