Git
Commit Message
Hashmark
Version Control
Git Best Practices

Start a Git commit message with a hashmark

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Git Commits and the Importance of Messages

Git is a distributed version control system that has become indispensable in software development. An essential part of its workflow involves making commits, which are snapshots of a project's code base at particular instances. These commits are accompanied by messages that ideally describe the changes made, reasons for those changes, and other pertinent details. However, just like code, commit messages need to follow certain best practices to maintain clarity and consistency.

Misconceptions About Commit Messages Starting with a

A common misconception is that Git allows commit messages to start with a hashmark (# ). It is pivotal to clarify that commit messages starting with a hashmark are treated as comments within Git’s environment and are typically ignored. To maintain clarity and efficiency in your repository's history, certain conventions and structures are recommended when writing effective commit messages.

Technical Explanation

How Git Interprets Commit Messages with #

  1. Pre-commit Hooks and Defaults:
    • In Git, when you use commands such as git commit , the default editor opens up for you to write your message. If you begin a line with # , Git interprets it as a comment and does not include it in the commit message. This is particularly useful when a text editor automatically includes lines like # Please enter the commit message for your changes. Lines starting with '#' will be ignored.
  2. Git Ignore Files:
    • By default, lines starting with # are comments in .gitignore files and in Git configurations, thus lines or commit messages prefixed with # are disregarded unless specifically overridden by configuration.
  3. Leverage Markdown:
    • Even though using # as the starting character in commit messages will cause them to be ignored, when integrating with platforms like GitHub that render commit history in markdown-like interfaces, using # for headers (e.g., ## Summary of Changes in extended commit descriptions) after the main message can improve the readability of project documentation.

Example: Incorrect Usage

Suppose you mistakenly use:

  • Limit the subject line to 50 characters.
  • Use the imperative mood (e.g., "Fix bug", not "Fixed bug" or "Fixes bug").
  • Separate subject from body with a blank line.
  • Wrap the body text at 72 characters.
  • Explain the ‘why’ more than the ‘what’.
  • If you are referring to tickets, issues, or pull requests, use the respective syntax and provide adequate details within the body.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.