diff --git a/main.sh b/main.sh index daf4853..1b01eb5 100755 --- a/main.sh +++ b/main.sh @@ -31,14 +31,25 @@ TMP_BRANCH="tmp-$RANDOM" git checkout -b $TMP_BRANCH git checkout $BRANCH +# use current branch last commit's author as the git identity +GIT_NAME=$(git show -s --format='%an' HEAD) +GIT_EMAIL=$(git show -s --format='%ae' HEAD) + # reset current branch to the root ROOT_HASH=$(git rev-list --max-parents=0 HEAD) git reset --hard $ROOT_HASH +# generate changes +MESSAGE='' +for rev in $(git rev-list $ROOT_HASH..$TMP_BRANCH); do + MESSAGE="$(git show --no-color --format=fuller --no-patch HEAD)\n$MESSAGE" +done +MESSAGE="Squashed the branch at $(date)\n$MESSAGE" + # merge-squash newest changes from the temporary branch git merge --squash $TMP_BRANCH git add . -git commit -m "$(date)" +git commit -c user.email=$GIT_EMAIL -c user.name=$GIT_NAME -m $MESSAGE # remove temporary branch git branch -D $TMP_BRANCH