DiffStats Type
The DiffStats interface represents aggregated diff statistics:
interface DiffStats {
files : number // Number of files changed
additions : number // Total lines added
deletions : number // Total lines deleted
binaryFiles : number // Number of binary files changed
}
Example Response
{
files : 3 ,
additions : 24 ,
deletions : 6 ,
binaryFiles : 0
}
diffStats
Get diff statistics for the working tree.
Function Signature
function diffStats () : Promise < DiffStats >
Returns
Aggregated diff statistics for working tree changes. Show DiffStats properties
Total lines added across all files.
Total lines deleted across all files.
Number of binary files changed.
Example
const stats = await git . diffStats ()
console . log ( ` ${ stats . files } files changed` )
console . log ( `+ ${ stats . additions } - ${ stats . deletions } ` )
if ( stats . binaryFiles > 0 ) {
console . log ( ` ${ stats . binaryFiles } binary files changed` )
}
diffStatsCommits
Get diff statistics between two commits.
Function Signature
function diffStatsCommits (
from : string ,
to : string
) : Promise < DiffStats >
Parameters
Returns
Aggregated diff statistics between the two commits.
Example
const stats = await git . diffStatsCommits ( "HEAD~1" , "HEAD" )
console . log ( `Last commit changed ${ stats . files } files` )
const releaseStats = await git . diffStatsCommits ( "v1.0.0" , "v1.1.0" )
console . log ( `Release added ${ releaseStats . additions } lines` )
diffStatsStaged
Get diff statistics for staged changes.
Function Signature
function diffStatsStaged () : Promise < DiffStats >
Returns
Aggregated diff statistics for staged changes.
Example
const stats = await git . diffStatsStaged ()
if ( stats . files > 0 ) {
console . log ( `Ready to commit:` )
console . log ( ` ${ stats . files } files` )
console . log ( ` + ${ stats . additions } - ${ stats . deletions } ` )
}
diffStatSummary
Get a short diff summary for working tree changes.
Function Signature
function diffStatSummary () : Promise < string >
Returns
Short stat summary string in Git’s standard format.
Example
const summary = await git . diffStatSummary ()
console . log ( summary )
// "3 files changed, 24 insertions(+), 6 deletions(-)"
diffStatStagedSummary
Get a short diff summary for staged changes.
Function Signature
function diffStatStagedSummary () : Promise < string >
Returns
Short stat summary string for staged changes.
Example
const summary = await git . diffStatStagedSummary ()
console . log ( `Staged: ${ summary } ` )
Comparison: Stats vs Summary
Function Return Type Use Case diffStats()DiffStats objectProgrammatic access to individual metrics diffStatSummary()stringHuman-readable summary for display
When to use which
Use diffStats() when you need to:
Make decisions based on specific metrics
Display custom formatted statistics
Calculate derived metrics
const stats = await git . diffStats ()
if ( stats . additions > 100 ) {
console . warn ( "Large change detected" )
}
const ratio = stats . additions / ( stats . deletions || 1 )
console . log ( `Add/Delete ratio: ${ ratio . toFixed ( 2 ) } ` )
Use diffStatSummary() when you need to:
Display Git’s standard summary format
Show quick overview to users
Log commit information
const summary = await git . diffStatSummary ()
console . log ( `Changes: ${ summary } ` )