Git Cohesion is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.
Git Cohesion
API ID: GitCohesionLanguages: Any
Targets: Architectures
The percentage of commits that are cohesive.
A cohesive commit is a commit whose changed files are all in the same architecture. A non-cohesive commit changes files across architectures. The value for a root architecture considers each sub-architecture as a separate group. The value for a non-root architecture forms a group with all descendants and everything else is a different group. So, for this sample architecture:
- Root
- A
- A1
- A2
- AA
- AA1
- AA2
- B
- B1
- B2
- A
When calculating cohesion for "Root":
- A commit touching A1 and A2 is cohesive because it only changes the sub-architecture "A".
- A commit touching A1 and B1 is not cohesive because it changes the sub-architectures "A" and "B".
- A commit touching A1 and AA2 is not cohesive because it changes the sub-architectures "A" and "AA".
When calculating cohesion for "A":
- A commit touching A1 and A2 is cohesive because it only changes files within "A".
- A commit touching A1 and B1 is not cohesive because it changes a file outside of "A" (in "B").
- A commit touching A1 and AA2 is cohesive because it only changes files within "A".
Note the difference in the 3rd bullet point for the two scenarios. For a root architecture, each nested architecture is considered as it's own architecture. For a non-root architecture, nested architectures within the target are considered as part of the target.
See also the Git Solution, the blog article ↗ describing the Git plugins, and the related coupling plugins which work on files: the interactive report Git Coupling, and the metrics Git Average Coupling, Git Max Coupling, Git Coupled Files and Git Strongly Coupled Files .