add git-split.sh
This commit is contained in:
25
scripts/git-split.sh
Executable file
25
scripts/git-split.sh
Executable 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
|
Reference in New Issue
Block a user