scitools.com

← Metric catalog

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: GitCohesion
Languages: 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:

When calculating cohesion for "Root":

  1. A commit touching A1 and A2 is cohesive because it only changes the sub-architecture "A".
  2. A commit touching A1 and B1 is not cohesive because it changes the sub-architectures "A" and "B".
  3. A commit touching A1 and AA2 is not cohesive because it changes the sub-architectures "A" and "AA".

When calculating cohesion for "A":

  1. A commit touching A1 and A2 is cohesive because it only changes files within "A".
  2. A commit touching A1 and B1 is not cohesive because it changes a file outside of "A" (in "B").
  3. 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 .