LoginSignup
1
0

More than 3 years have passed since last update.

gitのコミット履歴からStep数をカウントする(PowerShell版)

Posted at

たまーに改造規模をStep数で求められることがあるので、gitからカウントするコマンドをメモ。
linuxならawkを使ったやり方がいくつか出てくるが、WindowsかつGitBushとかも入れたくない場合向けに、PowerShellで。

git logの抽出

まずは git log で各ファイルごとの変更(追加行、削除行)をカウント。
コミット者(author)、期間(since、until)を指定して抽出している。
マージコミットは無視したいので、「no-merges」も指定。

PS C:\Work\XXXXX> git log --numstat --no-merges --pretty="" `
 --author="AAAAA" --author="BBBBB" --since=2020-01-01 --until=2020-07-01
9       3       AAA/aaa.cs
5       1       AAA/bbb.cs
13      6       BBB/ccc.cs
3       0       BBB/ddd.cs

CSV形式に変換

PowerShellの「ConvertFrom-Csv」を使ってCSV形式に変換する。

PS C:\Work\XXXXX> git log --numstat --no-merges --pretty="" `
 --author="AAAAA" --author="BBBBB" --since=2020-01-01 --until=2020-07-01 `
 | ConvertFrom-Csv -header add, delete, file -Delimiter "`t"
add delete file
--- ------ ----
9   3      AAA/aaa.cs
5   1      AAA/bbb.cs
13  6      BBB/ccc.cs
3   0      BBB/ddd.cs

合計のカウント

「Measure-Object -sum」でadd, delete列の合計を取得し、「Select-Object」で表示する。

PS C:\Work\XXXXX> git log --numstat --no-merges --pretty="" `
 --author="AAAAA" --author="BBBBB" --since=2020-01-01 --until=2020-07-01 `
 | ConvertFrom-Csv -header add, delete, file -Delimiter "`t" `
 | Measure-Object -sum add, delete `
 | Select-Object Property, Sum

Property  Sum
--------  ---
add        30
delete     10
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0