Created
January 6, 2016 20:32
-
-
Save LordZardeck/726ba7d3b52e7b2d2346 to your computer and use it in GitHub Desktop.
Git Line change calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: