Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Commit Hygiene Basics | Getting Started with Open Source
Git for Open Source Contributors

bookCommit Hygiene Basics

A strong commit history is essential for effective collaboration in open source projects. Writing meaningful commit messages helps maintainers and contributors understand the purpose of each change, review code efficiently, and track the evolution of a project. Good commit hygiene ensures that your work is easy to follow and builds trust with the community. Here are some guidelines for writing clear and useful commit messages:

  • Start with a short summary in the imperative mood, such as Fix typo in README or Add unit tests for user login;
  • Limit the summary line to 50 characters or fewer;
  • Add a blank line after the summary, then include a more detailed explanation if necessary;
  • Explain the reasoning behind the change, not just what was changed;
  • Reference issues or pull requests when relevant.

Clear commit messages matter because they make it easier for others to review your code, understand the context of changes, and identify when and why a bug was introduced. This is especially important in open source, where many contributors may be unfamiliar with the codebase or your specific changes.

12345678910
# Stage your changes before committing git add src/utils.py # Commit with a clear, well-formatted message git commit -m "Refactor utils.py: improve error handling Improve error handling in the file processing functions. This change ensures invalid files are skipped gracefully and logs detailed error messages for troubleshooting."
copy

Reviewing your commit history is an important habit for keeping your project organized. Use git log to see a list of recent commits, including their messages and associated metadata. This helps you verify that your commits are clear, relevant, and grouped logically. If you notice a typo or want to update the most recent commit message, you can use git commit --amend. This command opens your default text editor, allowing you to rewrite the previous commit message or add additional changes. Amending is useful for fixing small mistakes before pushing your work, but avoid amending commits that have already been shared with others to prevent confusion.

question mark

What is a key characteristic of a good commit message in open source projects?

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 4

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Suggested prompts:

Can you explain more about the imperative mood in commit messages?

What should I do if I need to update an older commit message, not just the most recent one?

Are there tools or plugins that help enforce good commit message practices?

bookCommit Hygiene Basics

Glissez pour afficher le menu

A strong commit history is essential for effective collaboration in open source projects. Writing meaningful commit messages helps maintainers and contributors understand the purpose of each change, review code efficiently, and track the evolution of a project. Good commit hygiene ensures that your work is easy to follow and builds trust with the community. Here are some guidelines for writing clear and useful commit messages:

  • Start with a short summary in the imperative mood, such as Fix typo in README or Add unit tests for user login;
  • Limit the summary line to 50 characters or fewer;
  • Add a blank line after the summary, then include a more detailed explanation if necessary;
  • Explain the reasoning behind the change, not just what was changed;
  • Reference issues or pull requests when relevant.

Clear commit messages matter because they make it easier for others to review your code, understand the context of changes, and identify when and why a bug was introduced. This is especially important in open source, where many contributors may be unfamiliar with the codebase or your specific changes.

12345678910
# Stage your changes before committing git add src/utils.py # Commit with a clear, well-formatted message git commit -m "Refactor utils.py: improve error handling Improve error handling in the file processing functions. This change ensures invalid files are skipped gracefully and logs detailed error messages for troubleshooting."
copy

Reviewing your commit history is an important habit for keeping your project organized. Use git log to see a list of recent commits, including their messages and associated metadata. This helps you verify that your commits are clear, relevant, and grouped logically. If you notice a typo or want to update the most recent commit message, you can use git commit --amend. This command opens your default text editor, allowing you to rewrite the previous commit message or add additional changes. Amending is useful for fixing small mistakes before pushing your work, but avoid amending commits that have already been shared with others to prevent confusion.

question mark

What is a key characteristic of a good commit message in open source projects?

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 4
some-alt