From 09461a4c2ae3d3cc8e9d6d4eafd6762ded92ce39 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Mon, 17 Jun 2024 10:32:44 +0200 Subject: [PATCH] add git-split.sh --- scripts/git-split.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 scripts/git-split.sh diff --git a/scripts/git-split.sh b/scripts/git-split.sh new file mode 100755 index 0000000..8a14fa7 --- /dev/null +++ b/scripts/git-split.sh @@ -0,0 +1,25 @@ +#!/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" + +git mv "$from" "$to" +git commit -n -m "Split history $from to $to - rename file to target-name" +REV=$(git rev-parse HEAD) +git reset --hard HEAD^ +git mv "$from" temp +git commit -n -m "Split history $from to $to - rename source-file to temp" +git merge "$REV" +git commit -a -n -m "Split history $from to $to - resolve conflict and keep both files" +git mv temp "$from" +git commit -n -m "Split history $from to $to - restore name of source-file" + +exit 0