Skip to content

Instantly share code, notes, and snippets.

@poke
Created November 29, 2015 15:59
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poke/237d098018cdf9889269 to your computer and use it in GitHub Desktop.
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
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
Copy link

Can we use this to upload old projects in the backdate?

@poke
Copy link
Author

poke commented May 8, 2021

@ 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