To display the total number of commits contributed by each contributor in a Git repository, you can use several methods, including command-line tools and GitHub's web interface. Here’s how you can do it using the command line:
Method 1: Using Git Command Line
1. Open your terminal or command prompt.
2. Navigate to your repository directory:
cd /path/to/your/repo
3. Run the following command:
git shortlog -s -n
Here's what this command does:
- shortlog: Summarizes the commit logs.
- -s: Produces a short output with the number of commits.
- -n: Sorts the output based on the number of commits, in descending order.
Method 2: Using GitHub Web Interface
If your repository is hosted on GitHub, you can also see contributors' stats directly on the website:
1. Navigate to your GitHub repository.
2. Click on the “Insights” tab.
3. Select “Contributors” from the sidebar.
This will display a graph of contributions by each contributor along with the total number of commits per contributor.
Method 3: Using Python Script (Advanced)
If you prefer to automate this task or want to process data programmatically, you can use a Python script with the GitPython library:
1. Install GitPython:
pip install GitPython
2. Create a Python script:
import git
repo = git.Repo('path/to/your/repo')
commits = repo.iter_commits()
contributor_commits = {}
for commit in commits:
author = commit.author.name
contributor_commits[author] = contributor_commits.get(author, 0) + 1
for author, count in contributor_commits.items():
print(f"{author}: {count} commits")
3. Run the script in your terminal:
python script_name.py
This will display the total number of commits contributed by each contributor.
Conclusion
You can choose any of these methods depending on your preference and the tools you have at hand. The command line and GitHub web interface are the most straightforward approaches, while