Script
The following script splits a file HEADinto a file:
#!/bin/bash
set -e
LF=$'\n'
SHA=$(git rev-parse --short HEAD)
MSG=$(git show -s --format=%B HEAD)
set -f; IFS=$'\n'
FILES=($(git diff-tree --no-commit-id --name-only -r HEAD))
set +f; unset IFS
git reset HEAD^
for f in "${FILES[@]}"; do
git add "$f"
git commit -m "$SHA $f$LF$LF$MSG"
done
The generated commit messages have the form:
<original SHA> <file name>
<original commit message>
Using
The following assumes that you can work the script above as git-split.
, :
git rebase --interactive --exec git-split <branch>
, :
p Commit to split
x git-split
script .