SourceTree Custom Action
Last updated
I needed to send a co-worker a zip of a specific commit while I was on PTO. The goal was a package they could unzip at the project root and get only the modified files in the correct directory structure — not a full git archive, just the diff as files.
Unzipping at the project root gives you only what changed, with paths intact:
docroot/
└── web/
└── app/
└── themes/
└── mytheme/
├── functions.php
├── inc/
│ ├── acf.php
│ └── cors.php
├── index.php
└── style.cssThe script
SourceTree runs external scripts. Save this as git-zip-commit.sh somewhere stable (e.g. your home folder):
# Ensure we have a commit hash
if [ -z "$1" ]; then
echo "Error: No commit hash provided."
exit 1
fi
COMMIT_SHA="$1"
# 1. Added "-m" to support merge commits
# 2. Capture the file list into a variable first
FILES=$(git diff-tree -r --no-commit-id --name-only --diff-filter=d -m "$COMMIT_SHA")
# Check if the file list is empty
if [ -z "$FILES" ]; then
echo "Error: No modified files found for commit $COMMIT_SHA."
echo "This prevents zipping the entire repository by mistake."
exit 1
fi
# Run the archive command only with the specific files
git archive -o patch.zip "$COMMIT_SHA" $FILES
echo "Success! Created patch.zip with only modified files."Make it executable:
chmod +x /path/to/git-zip-commit.shConfigure SourceTree
- Open SourceTree → Preferences (Mac) or Tools → Options (Windows).
- Go to the Custom Actions tab and click Add.
- Set:
- Menu Caption: Zip Commit for Deployment
- Script to Run: path to
git-zip-commit.sh - Parameters:
$SHA
- Click OK.
How to use it
Right-click the commit you want to package in the history graph.

Hover Custom Actions and choose Zip Commit for Deployment.

SourceTree writes patch.zip to your repository root.
Optional: timestamped filenames
To avoid overwriting previous patches, change the archive line in the script to:
git archive -o "patch-$(date +%Y%m%d-%H%M)-${COMMIT_SHA:0:7}.zip" "$COMMIT_SHA" $FILES