Skip to content

Instantly share code, notes, and snippets.

@LionsAd
Last active August 14, 2020 20:19
Show Gist options
  • Save LionsAd/035e39d9a33f7a942956e4d6d84b3e1e to your computer and use it in GitHub Desktop.
Save LionsAd/035e39d9a33f7a942956e4d6d84b3e1e to your computer and use it in GitHub Desktop.
Re-create commit history of one folder including all subcommits with 2nd chance for conflicting merges
RANGE="$1"
NAME="$2"
SITE="$3"
OUTPUT="$4"
DIR="docroot/sites/all/modules/custom/${NAME}/"
# Get a list of all relevant commits
LIST=$(git log --oneline --first-parent --reverse ${RANGE} -- ${DIR});
I=0;
IFS=$'\n';
for ITEM in ${LIST}
do
NNNN=$(printf "%04d\n" $I)
COMMIT=$(echo "${ITEM}" | sed 's|^\([^ ]*\) \(.*\)|\1|')
RAW_TITLE=$(echo "${ITEM}" | sed 's|^\([^ ]*\) \(.*\)|\2|')
TITLE=$(echo "${SITE} - ${RAW_TITLE}")
FILENAME_TITLE=$(echo "${TITLE}" | sed 's|[ -/~]|-|g' | sed 's|--*|-|g' | sed 's|^\(.\{52\}\).*|\1|')
FILENAME="${OUTPUT}/${NNNN}-${FILENAME_TITLE}_${COMMIT}.patch"
MERGE_FILENAME=${FILENAME/.patch/.merge}
CHANCE_FILENAME=${FILENAME/.patch/.chance}
echo "${FILENAME}";
git log --pretty=email -m --first-parent ${COMMIT}~1..${COMMIT} -- "${DIR}" | sed "s|Subject: \[PATCH\] |Subject: [SYNC] ${SITE}@${COMMIT}: |" > "${MERGE_FILENAME}"
git format-patch -M -k --stdout ${COMMIT}~1..${COMMIT} -- "${DIR}" | sed "s|${DIR}||g;" > "${FILENAME}"
git log -p --pretty=email -m --first-parent --stat ${COMMIT}~1..${COMMIT} -- "${DIR}" | sed "s|${DIR}||g; s|Subject: \[PATCH\]|Subject: [PATCH] SQUASH ${SITE}@${COMMIT}: |" > "${CHANCE_FILENAME}"
I=$(($I+1));
done
# OLD:
#git log -p --pretty=email --stat ${COMMIT}~1..${COMMIT} -- "${DIR}" | sed "s|${DIR}||g; s|Subject: \[PATCH\]|Subject: |" > "${FILENAME}";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment