Git下文件(夹)时间全部错误更新的恢复方法
1. 让 Git 允许输出中文(一劳永逸)
1
| git config --global core.quotepath false
|
2. 运行恢复脚本
直接把下面这段完整的代码再次复制粘贴进去运行:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $OutputEncoding = [System.Text.Encoding]::UTF8
git ls-files | ForEach-Object { $file = $_ $gitTimeStr = git log -1 --format=%cd --date=iso $file if ($gitTimeStr -and (Test-Path -LiteralPath $file)) { $gitTime = [DateTime]::Parse($gitTimeStr) Set-ItemProperty -LiteralPath $file -Name CreationTime -Value $gitTime Set-ItemProperty -LiteralPath $file -Name LastWriteTime -Value $gitTime Set-ItemProperty -LiteralPath $file -Name LastAccessTime -Value $gitTime Write-Host "已完美恢复中文文件时间: $file -> $gitTimeStr" -ForegroundColor Green } }
|
在要批量更改创建时间的文件夹下进入powershell
