Created
February 28, 2025 21:33
-
-
Save pwalkr/b1ab917f0226ca0b1b50b464fbcebc2d to your computer and use it in GitHub Desktop.
Apply git patches to alternative folders in a repository
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
#!/bin/sh | |
# This script applies a git commit cherry-pick style from one path to another. | |
# A patch is generated relative to the source folder, and reapplied on the | |
# destination folder. | |
# | |
# This is useful for promotion in infrastructure-as-code (IaC) implementations | |
# using folder-per-environment layouts. | |
# | |
# TODO: apply backlink to source commit in message, and potentially message | |
# replacement e.g. to replace environmental keywords. | |
src="$1" | |
dst="$2" | |
ref="$3" | |
#set -ex | |
cd "$src" | |
git format-patch -1 "$ref" --relative --stdout \ | |
| git am --directory "$dst" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment