Created
September 5, 2018 09:15
-
-
Save jdeniau/7dbdac3cf5d7c2fc91c0aa71980c6385 to your computer and use it in GitHub Desktop.
Split commit by file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git rebase --interactive --exec ./split.sh HEAD~1 # HEAD~1 can be replace by any commit number, this will split by commit + by file in this case |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" --no-verify | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment