Last active
November 10, 2020 00:49
-
-
Save zlatko-minev/2629929b8514780b71dba850503dacac to your computer and use it in GitHub Desktop.
Splitting a Git commit into one commit per file
This file contains 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 | |
# Pretty much script from | |
# https://hisham.hm/2019/02/12/splitting-a-git-commit-into-one-commit-per-file/ | |
# but modified to work with files that have spaces in their names | |
message="$(git log --pretty=format:'%s' -n1)" | |
git status --porcelain --untracked-files=no | while read status file | |
do | |
printf "\n" | |
echo "${status} ${file}" | |
filenm="$(echo "$file" | tr -d '"')" # strip " and add ' | |
if [ "$status" = "M" ] | |
then | |
git add "${filenm}" | |
git commit -n "${filenm}" -m "update of $file: $message" | |
elif [ "$status" = "A" ] | |
then | |
echo " -> File added. Not doing anything right now." | |
# git add "${filenm}" | |
# git commit -n "${filenm}" -m "added $file: $message" | |
elif [ "$status" = "D" ] | |
then | |
echo " -> File removed. Not doing anything right now." | |
# git rm "${filenm}" | |
# git commit -n "${filenm}" -m "removed $file: $message" | |
else | |
echo " -> WARNING: unknown status $file" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment