Skip to content

Instantly share code, notes, and snippets.

@LordZardeck
Created January 6, 2016 20:32
Show Gist options
  • Save LordZardeck/726ba7d3b52e7b2d2346 to your computer and use it in GitHub Desktop.
Save LordZardeck/726ba7d3b52e7b2d2346 to your computer and use it in GitHub Desktop.
Git Line change calculator
#!/usr/bin/env node
"use strict";
let exec = require("child_process").exec;
let args = process.argv.slice(2);
if(args.length <= 0) {
console.error("You must specify at least one commit to track back to.");
return;
}
exec(`git log ${args[0]}..${args[1] || "HEAD"} --oneline --shortstat | grep "changed,"`, (error, stdout) => {
let input = stdout.toString().split("\n");
let totalChanges = input.filter(line => line.indexOf('changed,') >= 0).map(line =>
line.substr(line.indexOf('changed,') + 8)
.replace(/(insertion(s)?\(\+\))/g, "")
.replace(/(deletion(s)?\(\-\))/g, "")
.split(",")
.map(count => parseInt(count.trim()))
.reduce((a, b) => a + b, 0)
).reduce((a, b) => a + b, 0);
console.log(`Total changes across ${input.length} commits: ${totalChanges}`);
});
@LordZardeck
Copy link
Author

Will sum up every addition and deletion across every commit, as far back as you specify. Will default to HEAD, unless you specify a end commit as well as a begin commit. Requires Node.js 4+.

Usage:

count-changes <begin-commit> <end-commit="HEAD">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment