add git-split.sh

This commit is contained in:
2024-06-17 10:32:44 +02:00
parent f169c0a5c6
commit 09461a4c2a

25
scripts/git-split.sh Executable file
View File

@@ -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