-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit_historical.ps1
More file actions
30 lines (21 loc) · 934 Bytes
/
commit_historical.ps1
File metadata and controls
30 lines (21 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$ErrorActionPreference = "Stop"
$statusOutput = git status --porcelain
foreach ($line in $statusOutput) {
if ([string]::IsNullOrWhiteSpace($line)) { continue }
$file = $line.Substring(3).Trim()
if ($file.StartsWith('"') -and $file.EndsWith('"')) {
$file = $file.Substring(1, $file.Length - 2)
}
if (Test-Path $file) {
$lastWrite = (Get-Item $file).LastWriteTime
$dateString = $lastWrite.ToString("s") # ISO 8601 string sortable
$rfc2822Date = $lastWrite.ToString('r') # RFC1123 format which git accepts nicely
Write-Host "Committing $file with date $rfc2822Date"
git add $file
$env:GIT_AUTHOR_DATE = $dateString
$env:GIT_COMMITTER_DATE = $dateString
$commitMsg = "Update $file based on historical changes"
git commit -m $commitMsg --date="$dateString"
}
}
git push origin HEAD