DEV Community

Rogério Rodrigues de Alcântara
Rogério Rodrigues de Alcântara

Posted on • Edited on

:wq cheats/git-commits

Git Commits

7 rules of a great Git commit message

  • #1 Keep in mind: This has all been said before.
  • #2 Separate subject from body with a blank line
  • #3 Limit the subject line to 50 characters
  • #4 Capitalise the subject line
  • #5 Do not end the subject line with a period
  • #6 Use the imperative mood in the subject line
  • #7 Wrap the body at 72 characters
  • #8 Use the body to explain what and why vs. how

Commit message structure

<type>[optional scope]: <Description>

[optional body]

[optional footer(s)]
Enter fullscreen mode Exit fullscreen mode

Examples

Commit with description and breaking change footer.

feat: Allow provided config object to extend other configs

BREAKING CHANGE: `extends` key in the config file is now used for extending other config files
Enter fullscreen mode Exit fullscreen mode

Commit with ! to draw attention to breaking change.

feat!: Send an email to the customer when the product is shipped
Enter fullscreen mode Exit fullscreen mode

Commit with scope and ! to draw attention to breaking change.

feat(api)!: Send email to the customer when product is shipped
Enter fullscreen mode Exit fullscreen mode

Commit with both! And BREAKING CHANGE footer.

chore!: Drop support for Node 6

BREAKING CHANGE: use JavaScript features not available in Node 6.
Enter fullscreen mode Exit fullscreen mode

Commit with nobody

docs(CHANGELOG): Correct spelling
Enter fullscreen mode Exit fullscreen mode

Commit with scope

feat(lang): Add Polish
Enter fullscreen mode Exit fullscreen mode

Commit with a multi-paragraph body and multiple footers.

fix(requests): Prevent racing

Introduce a request ID and a reference to the latest request.

Also:
- Dismiss incoming responses other than from the latest request.
- Remove timeouts, which were used to mitigate the racing issue but are obsolete now.

Refs: #123
Enter fullscreen mode Exit fullscreen mode

Use GitHub Copilot for Better Commit Messages in VSCode

Add to settings.json:

    // https://medium.com/medialesson/setting-up-github-copilot-for-better-commit-messages-in-vs-code-82d73fb6b016
    "github.copilot.chat.commitMessageGeneration.instructions": [
        { "text": "Use conventional commit format: <type>[(scope)]: <Subject>\n\n[optional body]\n\n[optional footer(s)]" },
        { "text": "Use types: feat, fix, docs, style, ref, test, revert, chore, ci, build, perf, git" },
        { "text": "Include scope when relevant (e.g.: 'api', 'ui', 'auth', 'admin/users')" },
        { "text": "Separate subject from body with a blank line" },
        { "text": "The subject should use the imperative mood, be capitalised, short, clear, concise, descriptive, meaningful, and communicate the context surrounding a change" },
        { "text": "Limit the subject line to 50 characters" },
        { "text": "Do not end the subject line with a period" },
        { "text": "The body should explain what and why vs. how" },
        { "text": "Wrap the body at 72 characters" },
        { "text": "Reference issue numbers with # prefix" },
        { "text": "Use the footer to reference breaking changes with 'BREAKING CHANGE: <description>'" },
        { "text": "Use the footer to reference issues with 'Closes #<issue-number>'" },
        { "text": "Use the footer to reference links that may exceed 72 characters with 'More: https://very.long.link/lorem-ipsum-excepteur-anim-dolore-et-laborum-officia-nostrud-nisi-tempor-in.-Sint-laboris-ex-ea-ex/'" },
        { "text": "Follow the constraints defined in the gitlint configuration, in order of precedence: ./.gitlint, ~/.config/gitlint/gitlint.cfg" }
    ],
Enter fullscreen mode Exit fullscreen mode

Tooling


References

Top comments (0)