#!/usr/bin/env bash # https://stackoverflow.com/questions/40698651/how-to-split-every-commit-by-file # Split HEAD commit into multiples with single file in it. # # If you want to split a single commit during an interactive rebase, use it like this: # p Commit to split # x git-split set -e SHA=$(git rev-parse --short HEAD) git reset HEAD^ git diff-tree --no-commit-id --name-only -r "$SHA" | while read -r f; do git add "$f" GIT_EDITOR="echo '0a\n$SHA $f\n\n.\nw' | ed -s" git commit -c "$SHA" --no-verify done