Skip to main content

Description

dvc.api.all_commits() returns a list of all Git commit SHAs in a DVC repository. This allows you to iterate over the entire commit history to track how data, models, and metrics have evolved.

Signature

def all_commits(repo: Optional[str] = None) -> list[str]

Parameters

repo
str
default:"None"
Location of the DVC repository. Defaults to the current project (found by walking up from the current working directory tree).Can be:
  • Local file system path
  • URL (HTTP/HTTPS)
  • Git SSH URL (e.g., user@server:project.git)

Returns

commits
list[str]
List of Git commit SHAs in the repository

Examples

List commits in current repository

import dvc.api

commits = dvc.api.all_commits()
print(f"Found {len(commits)} commits")
print(f"Latest commit: {commits[0][:7]}")

Track metric evolution over time

import dvc.api
import pandas as pd

commits = dvc.api.all_commits()

results = []
for commit in commits[:10]:  # Last 10 commits
    try:
        metrics = dvc.api.metrics_show(rev=commit)
        results.append({
            'commit': commit[:7],
            'accuracy': metrics.get('metrics.json', {}).get('accuracy')
        })
    except Exception:
        continue

df = pd.DataFrame(results)
print(df)

Compare data across commit history

import dvc.api

repo_url = "https://github.com/example/ml-project"
commits = dvc.api.all_commits(repo=repo_url)

# Check last 5 commits
for commit in commits[:5]:
    print(f"\nCommit: {commit[:7]}")
    
    try:
        params = dvc.api.params_show(repo=repo_url, rev=commit)
        print(f"  Learning rate: {params.get('train', {}).get('lr')}")
    except Exception as e:
        print(f"  Error: {e}")

Build commit history report

import dvc.api
from datetime import datetime

commits = dvc.api.all_commits()

print(f"Repository has {len(commits)} commits")
print(f"\nRecent commits:")

for commit in commits[:20]:
    try:
        metrics = dvc.api.metrics_show(rev=commit)
        if 'metrics.json' in metrics:
            acc = metrics['metrics.json'].get('accuracy', 'N/A')
            print(f"  {commit[:7]}: accuracy={acc}")
    except Exception:
        pass

Use cases

Historical analysis

Analyze how metrics and data evolved over the project history

Performance tracking

Track model performance improvements across commits

Data lineage

Trace data provenance through commit history

Audit and compliance

Maintain audit trail of all changes to data and models

Build docs developers (and LLMs) love