Skip to content

Instantly share code, notes, and snippets.

@halityurttas
Created October 2, 2020 15:24
Show Gist options
  • Save halityurttas/686e56febe38f148fe7e37fee5705767 to your computer and use it in GitHub Desktop.
Save halityurttas/686e56febe38f148fe7e37fee5705767 to your computer and use it in GitHub Desktop.
Copy diff files to target with folder hierarchy from a text file
$des = "d:\diff_backup\"
$safe = Get-Content ".\diff.txt"
$safe | ForEach-Object{
#find drive-delimeter
$first=$_.IndexOf(":\");
if($first -eq 1){
#stripe it
$newdes=Join-Path -Path $des -ChildPath @($_.Substring(0,1)+$_.Substring(2))[0]
}
else{
$newdes=Join-Path -Path $des -ChildPath $_
}
$folder=Split-Path -Path $newdes -Parent
$err=0
#check if folder exists"
$void=Get-Item $folder -ErrorVariable err -ErrorAction SilentlyContinue
if($err.Count -ne 0){
#create when it doesn't
$void=New-Item -Path $folder -ItemType Directory -Force -Verbose
}
$void=Copy-Item -Path $_ -destination $newdes -Recurse -Container -Force -Verbose
}
@halityurttas
Copy link
Author

Generate diff.txt for

$ git diff --name-status firstbranchorcommit yourbranchorcommit > diff.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment