Created
November 29, 2015 15:59
-
-
Save poke/237d098018cdf9889269 to your computer and use it in GitHub Desktop.
git-backdate to create a repository from a folder, creating a commit for each file backdated to its file modification date
This file contains hidden or 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
Param([string] $Folder) | |
Write-Host 'Backdating files in folder' $Folder -ForegroundColor Green | |
Push-Location $Folder | |
git init | |
git commit --allow-empty -m 'Initialize repository' | |
Write-Host 'Looking for files: ' -NoNewLine -ForegroundColor Blue | |
$files = Get-ChildItem * -Recurse | ? { !$_.PSIsContainer } | sort LastWriteTime | |
Write-Host $files.Length -NoNewLine -ForegroundColor Yellow | |
Write-Host ' files found' -ForegroundColor Blue | |
Write-Host 'Committing files backdated to their last write time' -ForegroundColor Blue | |
$files | % { | |
git add $_.FullName | |
$date = $_.LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss') | |
$env:GIT_COMMITTER_DATE = $env:GIT_AUTHOR_DATE = $date | |
git commit -m ('Backdating: ' + $date) | |
} | |
$env:GIT_COMMITTER_DATE = $env:GIT_AUTHOR_DATE = $null | |
Pop-Location | |
Write-Host 'Done.' -ForegroundColor Green |
@ AbhishekSharma51 Sure, feel free to use or modify the script for your needs! See also this answer on Stack Overflow for some more details on how to use it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can we use this to upload old projects in the backdate?