How to use the command git fame (with examples)

How to use the command git fame (with examples)

Git fame is a command-line tool that calculates and pretty-prints the contributions of each contributor to a Git repository. It provides valuable insights into how much each contributor has contributed to the project.

Use case 1: Calculate contributions for the current Git repository

Code:

git fame

Motivation: This use case allows you to quickly calculate the contributions made by each contributor to the current Git repository. It provides a summary of the number of commits, insertions, deletions, and files changed by each contributor.

Explanation: The git fame command without any additional arguments calculates the contributions for the current Git repository.

Example output:

Contributor            Commits     +      -     ++     --    Files
Author 1               1234       567    890    123    456   78
Author 2               567        123    456    789    012   34

Use case 2: Exclude files/directories that match the specified regular expression

Code:

git fame --excl "regular_expression"

Motivation: Sometimes, you may want to exclude certain files or directories from the contribution calculations. This becomes useful when you want to focus only on specific parts of the codebase.

Explanation: The --excl flag followed by a regular expression allows you to exclude files or directories that match the specified regular expression from the contribution calculations.

Example output:

Contributor            Commits     +      -     ++     --    Files
Author 1               567        123    456    789    012   34
Author 2               345        678    901    234    567   89

Use case 3: Calculate contributions made after the specified date

Code:

git fame --since "3 weeks ago|2021-05-13"

Motivation: This use case is helpful when you want to calculate the contributions made by each contributor after a specific date. It allows you to track recent contributions and analyze the impact of recent changes.

Explanation: The --since flag followed by a date (in relative or absolute format) allows you to calculate the contributions made after the specified date.

Example output:

Contributor            Commits     +      -     ++     --    Files
Author 1               345        678    901    234    567   89
Author 2               123        456    789    012    345   67

Use case 4: Display contributions in the specified format

Code:

git fame --format pipe|yaml|json|csv|tsv

Motivation: By default, the contributions are displayed in a tabulated format. However, in some scenarios, you may want to have the contributions in a different format, such as pipe-separated, YAML, JSON, CSV, or TSV. This use case allows you to customize the output format according to your preference.

Explanation: The --format flag followed by the desired format (pipe, yaml, json, csv, or tsv) specifies the output format for the contributions.

Example output (with format as pipe):

Contributor|Commits|+|-|++|--|Files
Author 1|1234|567|890|123|456|78
Author 2|567|123|456|789|012|34

Use case 5: Display contributions per file extension

Code:

git fame --bytype

Motivation: This use case allows you to analyze the contributions by file extension. It provides insights into which file types contributors are primarily working on and how their contributions differ across different file types.

Explanation: The --bytype flag displays the contributions grouped by file extension, showing the number of commits, insertions, deletions, and files changed for each file type.

Example output:

File Extension  Commits     +      -     ++     --    Files
.js             1000       500    400    100    50    80
.css            500        200    100    50     30    20

Use case 6: Ignore whitespace changes

Code:

git fame --ignore-whitespace

Motivation: Whitespace changes, such as trailing whitespaces or indentation changes, do not reflect the actual code contributions made by contributors. By using this use case, you can exclude whitespace changes from the contributions calculations to focus on meaningful code changes.

Explanation: The --ignore-whitespace flag tells git fame to ignore whitespace changes when calculating contributions.

Example output:

Contributor            Commits     +      -     ++     --    Files
Author 1               800        300    450    100    150   60
Author 2               600        200    350    50     100   50

Use case 7: Detect inter-file line moves and copies

Code:

git fame -C

Motivation: This use case helps identify situations where code changes have been moved or copied from one file to another. It provides insights into how code is being refactored or reused across different files.

Explanation: The -C option tells git fame to detect inter-file line moves and copies when calculating contributions.

Example output:

Contributor            Commits     +      -     ++     --    Files
Author 1               450        200    200    50     50    40
Author 2               350        150    150    30     20    30

Use case 8: Detect intra-file line moves and copies

Code:

git fame -M

Motivation: In certain cases, code changes may occur within the same file where lines of code are moved or copied. This use case helps identify such changes and provides insights into how code is being rearranged or duplicated within a file.

Explanation: The -M option tells git fame to detect intra-file line moves and copies when calculating contributions.

Example output:

Contributor            Commits     +      -     ++     --    Files
Author 1               250        100    100    20     30    25
Author 2               200        80     80     15     25    20

Conclusion:

The git fame command is a powerful tool for analyzing and visualizing Git repository contributions. With various options and flags, it allows you to customize the calculations and output format according to your specific needs. Whether you want to track recent contributions, exclude certain files, analyze contributions by file type, or detect code moves and copies, git fame provides valuable insights into the contributions made by each contributor.

Related Posts

How to use the command rexec (with examples)

How to use the command rexec (with examples)

rexec is a command-line tool used to execute commands on a remote host.

Read More
How to use the command "guile" (with examples)

How to use the command "guile" (with examples)

Guile is a Scheme interpreter that allows users to interact with the Scheme programming language.

Read More
How to use the command 'equery' (with examples)

How to use the command 'equery' (with examples)

The ’equery’ command is a tool used in Gentoo Linux for viewing information about Portage packages.

Read More