From c6ed9b68f59a47251b0bdf975b664eabc5279ee0 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Mon, 17 Jun 2024 15:17:36 +0200 Subject: [PATCH] add git-split.sh --- scripts/git-split.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 scripts/git-split.sh diff --git a/scripts/git-split.sh b/scripts/git-split.sh new file mode 100644 index 0000000..fab25d7 --- /dev/null +++ b/scripts/git-split.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# +# Copy a git file, keeping history. +# Source: https://stackoverflow.com/a/53849613/3079831 + +if (( $# != 2 )) ; then + echo "Usage: git-split.sh original copy" + exit 1 +fi + +from="$1" +to="$2" +branch="split-file" +tmp="$from-temp-copy" + +git switch -c "$branch" +git mv "$from" "$to" +git commit -n -m "Split $from to $to - step 1" + +#REV=$(git rev-parse HEAD) +git switch - + +git mv "$from" "$tmp" +git commit -n -m "Split $from to $to - step 2" +git merge "$branch" + +git commit -a -n -m "Split $from to $to - step 3" +git mv "$tmp" "$from" +git commit -n -m "Split file $from to $to - step 4" + +git branch -d "$branch" + +exit 0