Skip to content

Instantly share code, notes, and snippets.

@Hona
Created March 4, 2025 03:30
Show Gist options
  • Select an option

  • Save Hona/472c330236c5a7ca09313952236f905c to your computer and use it in GitHub Desktop.

Select an option

Save Hona/472c330236c5a7ca09313952236f905c to your computer and use it in GitHub Desktop.
$file = "src/path/mything.cs"
$outputFile = "file_history.csv"
"Date,Commit,Lines" | Out-File $outputFile
$log = git log --follow --name-status --pretty=format:"COMMIT:%H:%ad" --date=short -- "$file"
$currentPath = $file
foreach ($line in $log) {
if ($line.StartsWith("COMMIT:")) {
$parts = $line.Split(":")
$commit = $parts[1]
$date = $parts[2]
try {
$lines = (git show "$commit`:$currentPath" | Measure-Object -Line).Lines
"$date,$commit,$lines" | Out-File $outputFile -Append
} catch {}
}
elseif ($line -match "^R\d*\s+(.+)\s+(.+)$") {
$currentPath = $matches[1]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment