From 06ce0859cc17e2be66c685278f0f0695fc86e7c4 Mon Sep 17 00:00:00 2001 From: XIANJUN ZHU Date: Mon, 21 Oct 2019 16:16:44 -0400 Subject: [PATCH] feat: add prepare upstream script (#223) --- prepare-upstream-contribution.sh | 77 ++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 prepare-upstream-contribution.sh diff --git a/prepare-upstream-contribution.sh b/prepare-upstream-contribution.sh new file mode 100755 index 000000000..a9d1952c9 --- /dev/null +++ b/prepare-upstream-contribution.sh @@ -0,0 +1,77 @@ +#!/bin/bash +# Description: +# +# This script allows you to generate a baseline commit history maintains the +# original author / committor information before making upstream contribution. +# Inspired by https://stosb.com/blog/retaining-history-when-moving-files-across-repositories-in-git/ +# +# See usage for more detailed description. + +function usage() { +cat </dev/null; done; true;" ${START_COMMIT}..${END_COMMIT} +# Set the temp location as root +git filter-branch --prune-empty -f --subdirectory-filter ${TEMP_BRANCH}-newroot +# Add filtered off commits to the top of starting commit +git rebase ${START_COMMIT} + +# move files back to their original location and make a new commit +for f in $FILES; do + mv $(basename $f) $f 2>/dev/null + git add $f + git add $(basename $f) +done +git commit -m 'Move files back' +git checkout ${CURRENT_BRANCH} + +echo "The prepared branch is ${TEMP_BRANCH}. Use command below to view the history" +echo "" +echo " git log --oneline -n10 ${TEMP_BRANCH}" +echo ""