Skip to content

Instantly share code, notes, and snippets.

@jennings
Created August 5, 2019 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jennings/d491ceb17c58b716d5251ae7522bbd68 to your computer and use it in GitHub Desktop.
Save jennings/d491ceb17c58b716d5251ae7522bbd68 to your computer and use it in GitHub Desktop.
$ErrorActionPreference = "Stop"
function Main {
"This script creates a zip file that contains all files changed between two commits."
"Commits can be specified as commit IDs (SHA) or as branch names."
"For example: 'master' or 'ff39683ed6'"
""
$git_dir = Read-Host -Prompt "Git directory"
$to_commit = Read-Host -Prompt "Commit to deploy"
$from_commit = Read-Host -Prompt "Previously deployed commit"
pushd $git_dir
try {
$datestr = "{0:yyMMdd-HHmmss}" -f (get-date)
$export_filename = "export_$datestr.zip"
# All files that have been changed, excluding deleted files
$changed_files = git diff --name-only "$from_commit" "$to_commit" --diff-filter=d
# Deleted files, for listing
$deleted_files = git diff --name-only "$from_commit" "$to_commit" --diff-filter=D
# Create the export
git archive --output="$export_filename" $to_commit $changed_files
""
"Created $export_filename in $git_dir"
if ($deleted_files) {
"Deleted files:"
foreach ($filename in $deleted_files) {
" - $filename"
}
}
} finally {
popd
}
}
Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment