SZZ Algorithm Reference
Overview
The SZZ (Śliwerski-Zimmermann-Zeller) algorithm is a widely-used approach for identifying bug-introducing commits in software repositories. It works by analyzing bug-fixing commits and tracing back through version history to find the commits that introduced the buggy code.
Core Algorithm Steps
Identify Bug-Fixing Commit: Start with a commit that fixes a bug (typically identified through commit messages, issue trackers, or manual annotation)
Extract Modified Lines: Analyze the diff to identify which lines were deleted or modified in the fix
Blame Analysis: For each deleted/modified line, use git blame to trace back to the commit that originally introduced that line
Candidate Identification: The commits identified through blame are candidates for bug-introducing commits
Filtering: Apply heuristics to filter false positives
Ranking: Rank candidates by likelihood of being the actual bug-introducing commit
False Positive Patterns
Common sources of false positives that should be filtered:
Code Formatting and Style
- Whitespace changes
- Indentation adjustments
- Bracket placement
- Line breaks
Non-Functional Changes
- Comment additions/modifications
- Import statement reordering
- Code reorganization without logic changes
- Variable/function renaming
Refactoring Operations
- Code extraction to methods
- Code movement between files
- Structural changes without behavior modification
Filtering Heuristics
Commit Message Analysis
Look for keywords indicating non-bug-introducing changes:
- "refactor", "rename", "format", "style"
- "cleanup", "reorganize", "restructure"
- "reformat", "whitespace", "indent"
Line Content Analysis
Skip lines that are unlikely to contain bugs:
- Empty lines
- Lines with only braces
{ or }
- Import/include statements
- Comments (single-line and multi-line)
- Pure whitespace changes
Temporal Analysis
- Commits very close in time to the fix may be less likely to be bug-introducing
- Very old commits may have lower confidence if the code has changed significantly
Confidence Scoring
Factors that increase confidence:
- Multiple lines from the same commit were fixed
- The commit modified functional code (not comments/formatting)
- The commit message doesn't suggest refactoring
- The time gap between introduction and fix is reasonable
Factors that decrease confidence:
- Commit message suggests refactoring/formatting
- Only one line was modified
- The line contains only structural elements
- The commit is very recent or very old relative to the fix
Limitations
Tangled Changes: If a commit contains both bug-introducing and unrelated changes, SZZ may incorrectly attribute the entire commit
Indirect Bugs: Bugs caused by missing code or incorrect assumptions may not be detected
Refactoring: Heavy refactoring can break the blame chain, making it difficult to trace back to the original introduction
Multi-Commit Bugs: Bugs introduced across multiple commits may only identify the most recent contributor
False Fixes: If the "fix" commit doesn't actually fix the bug, the analysis will be incorrect
Best Practices
Verify Bug-Fix Commits: Ensure the starting commit actually fixes a bug (check issue trackers, test results)
Manual Review: Always manually review top candidates, especially for critical bugs
Context Analysis: Consider the broader context of the code change, not just the specific lines
Multiple Candidates: Present multiple candidates rather than assuming the top result is always correct
Iterative Refinement: Use domain knowledge to refine filtering heuristics for specific projects
Extensions and Variants
- MA-SZZ: Meta-data Aware SZZ that uses additional metadata
- RA-SZZ: Refactoring-Aware SZZ with improved refactoring detection
- AG-SZZ: Annotation Graph SZZ using program dependency graphs
- PyDriller-based: Modern implementations using PyDriller library
References
- Śliwerski, J., Zimmermann, T., & Zeller, A. (2005). "When do changes induce fixes?"
- Kim, S., et al. (2006). "Automatic identification of bug-introducing changes"
- Da Costa, D. A., et al. (2017). "A framework for evaluating the results of the SZZ approach"
1---2name: szz-algorithm-reference3description: The SZZ (Śliwerski-Zimmermann-Zeller) algorithm is a widely-used approach for identifying bug-introducing commits in software repositories.4---5# SZZ Algorithm Reference67## Overview89The SZZ (Śliwerski-Zimmermann-Zeller) algorithm is a widely-used approach for identifying bug-introducing commits in software repositories. It works by analyzing bug-fixing commits and tracing back through version history to find the commits that introduced the buggy code.1011## Core Algorithm Steps12131. **Identify Bug-Fixing Commit**: Start with a commit that fixes a bug (typically identified through commit messages, issue trackers, or manual annotation)14152. **Extract Modified Lines**: Analyze the diff to identify which lines were deleted or modified in the fix16173. **Blame Analysis**: For each deleted/modified line, use `git blame` to trace back to the commit that originally introduced that line18194. **Candidate Identification**: The commits identified through blame are candidates for bug-introducing commits20215. **Filtering**: Apply heuristics to filter false positives22236. **Ranking**: Rank candidates by likelihood of being the actual bug-introducing commit2425## False Positive Patterns2627Common sources of false positives that should be filtered:2829### Code Formatting and Style30- Whitespace changes31- Indentation adjustments32- Bracket placement33- Line breaks3435### Non-Functional Changes36- Comment additions/modifications37- Import statement reordering38- Code reorganization without logic changes39- Variable/function renaming4041### Refactoring Operations42- Code extraction to methods43- Code movement between files44- Structural changes without behavior modification4546## Filtering Heuristics4748### Commit Message Analysis49Look for keywords indicating non-bug-introducing changes:50- "refactor", "rename", "format", "style"51- "cleanup", "reorganize", "restructure"52- "reformat", "whitespace", "indent"5354### Line Content Analysis55Skip lines that are unlikely to contain bugs:56- Empty lines57- Lines with only braces `{` or `}`58- Import/include statements59- Comments (single-line and multi-line)60- Pure whitespace changes6162### Temporal Analysis63- Commits very close in time to the fix may be less likely to be bug-introducing64- Very old commits may have lower confidence if the code has changed significantly6566## Confidence Scoring6768Factors that increase confidence:69- Multiple lines from the same commit were fixed70- The commit modified functional code (not comments/formatting)71- The commit message doesn't suggest refactoring72- The time gap between introduction and fix is reasonable7374Factors that decrease confidence:75- Commit message suggests refactoring/formatting76- Only one line was modified77- The line contains only structural elements78- The commit is very recent or very old relative to the fix7980## Limitations81821. **Tangled Changes**: If a commit contains both bug-introducing and unrelated changes, SZZ may incorrectly attribute the entire commit83842. **Indirect Bugs**: Bugs caused by missing code or incorrect assumptions may not be detected85863. **Refactoring**: Heavy refactoring can break the blame chain, making it difficult to trace back to the original introduction87884. **Multi-Commit Bugs**: Bugs introduced across multiple commits may only identify the most recent contributor89905. **False Fixes**: If the "fix" commit doesn't actually fix the bug, the analysis will be incorrect9192## Best Practices93941. **Verify Bug-Fix Commits**: Ensure the starting commit actually fixes a bug (check issue trackers, test results)95962. **Manual Review**: Always manually review top candidates, especially for critical bugs97983. **Context Analysis**: Consider the broader context of the code change, not just the specific lines991004. **Multiple Candidates**: Present multiple candidates rather than assuming the top result is always correct1011025. **Iterative Refinement**: Use domain knowledge to refine filtering heuristics for specific projects103104## Extensions and Variants105106- **MA-SZZ**: Meta-data Aware SZZ that uses additional metadata107- **RA-SZZ**: Refactoring-Aware SZZ with improved refactoring detection108- **AG-SZZ**: Annotation Graph SZZ using program dependency graphs109- **PyDriller-based**: Modern implementations using PyDriller library110111## References112113- Śliwerski, J., Zimmermann, T., & Zeller, A. (2005). "When do changes induce fixes?"114- Kim, S., et al. (2006). "Automatic identification of bug-introducing changes"115- Da Costa, D. A., et al. (2017). "A framework for evaluating the results of the SZZ approach"