Common rules and best practices for Git commit comments

When using Git, there are some common rules and best practices that can help team members write better Git commit comments. Here are some common Git commit comment rules:

  1. Be concise: Comments should be concise and describe the changes in general. Avoid long comments and keep a line to no more than 50 characters in length.

  2. Use the present tense of verbs: Use the present tense of verbs to describe changes. For example, use "Fix" instead of "Fixed" or "Fixes".

  3. First Person: Use the first person to describe changes, such as "Add feature" instead of "Adds feature".

  4. Avoid meaningless comments: Comments should provide useful information, avoid meaningless comments such as "Update" or "Fix bug". Be as specific as possible.

  5. Use keywords: Use keywords in comments to identify the type of change that was made. For example, use "Add" to add a new feature, "Fix" to fix a bug, "Update" to update an existing feature, "Remove" to remove a feature, etc.

  6. Reference issue or task number: If your code change is related to a specific issue or task, you can reference the corresponding issue or task number in the comment. This helps to track and correlate code changes with specific issues or tasks.

  7. Segmented comments: For larger code changes, segmented comments can be used to better organize and describe the different parts of the change.

  8. Use English: To ensure understanding and consistency among team members, it is recommended to write Git commit comments in English.

These rules and best practices can help team members better understand and track code change history, improve code readability and maintainability.

Here are some examples of Git commit comments that demonstrate the proper format for comments:

  1. Add new features:

    Add user authentication feature
    
  2. Fix bugs:

    Fix null pointer exception in data processing
    
  3. Update an existing function:

    Update data validation logic for better error handling
    
  4. Remove function:

    Remove deprecated API endpoint
    
  5. To quote an issue or task number:

    Refactor database connection code (#123)
    
  6. Segmentation notes:

    Refactor user authentication code
    
    - Extract authentication logic into separate module
    - Improve password hashing algorithm
    

These example comments follow the rules of brevity, use of the present tense of verbs, first person, keywords, etc., and provide useful information to describe the changes made. Please adjust accordingly according to your specific situation and team requirements.

Guess you like

Origin blog.csdn.net/ChinaLiaoTian/article/details/131556358