Semantic Commit is a method used in software development. Its main purpose is to ensure that commit messages (i.e., messages associated with each change made to the code) are more meaningful and structured. This way, developers can more easily understand when, why, and what changes were made to the code.
Each commit message clearly describes the changes made. This way, while working on a project, you can quickly understand what changed in the code and why. For example, instead of saying 'just some edits made,' a clear explanation like 'new login page added' is provided.
When there is a bug in a project, it becomes much easier to find the changes that might have caused the issue by reviewing past commit messages. Meaningful and structured commit messages help you quickly locate and resolve errors.
Semantic Commit helps you see more clearly which changes were made in which version of the project. For example, when a new feature is added, the version number can be updated. This makes it easier to keep the project up to date.
When working with multiple people, having everyone write commit messages in the same way keeps the project organized. This way, one team member can more easily understand what another has done, increasing collaboration.
As the project grows, there may be hundreds or even thousands of commits. Meaningful commit messages make it easier to manage the large project and track changes over time.
First, after making changes to the files you're working on, you need to use the `git add` command in the terminal to include these files in the commit.
To add all files, enter the following command in the terminal:
git add .If you only want to add specific files:
git add <file-name>To commit the changes, you can use the following command in the terminal:
When writing a commit message that follows the Semantic Commit rules, here are the key things to pay attention to:
Commit Type: Indicate the type of change made (e.g., feat, fix, docs, etc.).
Scope (Optional): You can use scope to specify which module or component was changed.
Message Title: Briefly and concisely describe the change.
Example commit:
git commit -m "feat(auth): add user login functionality"After making a commit, you can push your changes to the remote repository using the following command in the terminal:
For example, if you're pushing to the main or dev branch:
git push origin mainsemanticcommit.com
Learn best practices for clear, concise commit messages to improve project organization, code readability, team collaboration, and version control.
react.dev
React enables the development of dynamic user interfaces with reusable components, enhancing performance and efficiency in web applications.
nextjs.org
Next.js allows you to build full-stack web applications using React's latest features and fast Rust-based JavaScript tooling, used by many large companies.
vuejs.org
React enables the development of dynamic user interfaces with reusable components, enhancing performance and efficiency.
freecodecamp.org
freeCodeCamp is a nonprofit platform offering free coding lessons and resources for web development and data science.
getbootstrap.com
The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
-
1. Understandability: Each commit message clearly states the purpose and reason for the change. For example, a message like "feat: Added new user login page" indicates that this commit was made to add a new feature.
-
2. Tracking the Code History: If a project has many developers working on it, each commit message makes the project’s history more transparent and easier to track. Knowing when a change was made helps in finding and fixing bugs.
-
3. Versioning and Automation: Semantic commit messages can help with automatic version updates (e.g., adding a new feature, fixing a bug). These messages make it easier to increase version numbers in an organized way (e.g., 1.2.0 → 1.3.0).
Each commit message should clearly express the purpose of the change. This helps other developers in the project to easily understand the reason for the changes. A good commit message avoids general terms like 'bug fix' or 'feature update' and clearly states what has been improved or fixed. Commit messages should also be concise. If necessary, additional explanations or references can be added after the commit message.
No, the scope is not mandatory. It is optional and can be used to indicate which section or module is affected by the change. However, in large projects or projects with multiple modules, using the scope can clarify the affected area and make the message more meaningful.
-
There are several methods to undo a commit:
-
Undo the last commit (soft reset):
git reset --soft HEAD~1* This command undoes the last commit but leaves the changes in your working directory.
-
Completely undo the last commit (hard reset):
git reset --hard HEAD~1* This command deletes both the commit and the changes.
-
Undo using the git revert command:
git revert* This command undoes a specific commit and creates a new commit.
You can undo the commit. Check the 'How do I undo a commit?' section for more detailed information.
Yes, commit messages should be in English, as it is a global language. This increases the understandability for all developers in the project and facilitates international collaboration in open-source projects.