An Interest In:
Web News this Week
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
Git Commit Patterns
The use of Git for us Devs is something essential, whether in personal projects, open source with many people or an entire community.
Given that, it's important that we usegit commit properly. Having a coherent and standardized language helps everyone involved in the project to understand the changes that have occurred.
In the image above, we see how harmful a poorly commented commit can be, since we fail to understand the nature of the change that occurred and the context of it. In the long run, the effect is even more damaging, as the maintainability of the software suffers due to inconsistencies in the scope of these changes, and how they have affected the project in the past.
With that in mind, let's talk a little about Conventional Commits Pattern.
What Is It?
Conventional Commitsis a simple convention forcommit messages, which follows a set of rules and helps projects to have an explicit and well-structuredcommit history.
How To Use It?
The rules are very simple, as shown below we have a type of commit, the context (scope) ofcommit and the message (subject) ofcommit.
!type(?scope): !subject<?body><?footer>
Thus, !
indicates the mandatory attributes and ?
indicates optional attributes.
Subject: Imperative instead of past tense
In this way we are telling our team what the commit will do if applied.
If applied, this commit will
If applied, this commit will change the markup, which makes a lot more sense than: If applied, this commit will changed the markup
Type: What are the types of commits
Thetypeisresponsible for telling us what change or iteration is being made, from the convention rules, we have the following types:
test
: indicates any type of creation or alteration of test codes.
Example:Creation of unit tests.feat
: indicates the development of a new feature for the project.
Example: Adding a service, functionality, endpoint, etc.refactor
: used when there is a code refactoring that does not have any impact on the system logic/rules.
Example:Code changes after acode reviewstyle
: used when there are code formatting and style changes that do not change the system in any way.
Example:Change thestyle-guide, change thelint convention, fix indentations, remove white spaces, remove comments, etcfix
: used when correcting errors that are generating bugs in the system.
Example:Apply a handling for a function that is not behaving as expected and returning an error.chore
: indicates changes to the project that do not affect the system or test files. These are developmental changes.
Example:Change rules foreslint, addprettier, add more file extensions to .gitignoredocs
: used when there are changes in the project documentation.
Example:add information in the API documentation, change theREADME, etc.build
: used to indicate changes that affect the project build process or external dependencies.
Example:Gulp, add/remove npm dependencies, etcperf
: indicates a change that improved system performance.
Example:changeForEachtoWhile, etcci
: used for changes in CI configuration files.
Example:Circle,Travis,BrowserStack, etcrevert
: indicates the reversal of apreviouscommit.
Note:
Only onetypepercommit;
Thetypeismandatory;
If you dont know which type to use, it is probably a big change and it is possible to split this commit into two or more commits;
The difference between
build
andchore
can be quite subtle and can lead to confusion, so we must be aware of the correct type. In the case of Node.js, for example, we can think that when there is an addition/change to a certain development dependency present indevDependencies
,we usechore
. For changes/additions of common dependencies to the project, and that have a direct and real impact on the system, we usebuild
.
Scope: contextualizing thecommit
At this point and following past conventions we managed to understand thetypeof change that was made in thecommit(commit type) and clearly understand what thecommitwill bring if applied (commit subject).
Even though thescopeis not mandatory, it can be used to contextualize thecommitand bring less responsibility to thesubject, making it as brief and concise as possible. Remembering that thescopemust be inserted in thecommitbetween parentheses.
Note: Scopes must be separated with /
Conclusion
I wrote this article in order to record one of my learnings (they were just some notes in the notion app), but I hope it can help other devs out there.
Original Link: https://dev.to/jasonh33/git-commit-patterns-5dm7
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To