Created
August 13, 2015 23:37
-
-
Save Mikulas/a23f58c5ec30c74f2793 to your computer and use it in GitHub Desktop.
git-afix is a smart fixup tool that creates fixup commit with each staged file. Fixed revision is last rev that the file was changed in.
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 -euo pipefail | |
IFS=$'\n\t' | |
fixups="" | |
for FILE in $(git --no-pager diff --name-only --cached); do | |
# TODO limit to last merge commit | |
REF=$(git log -n 1 --follow --no-merges --pretty="format:%H" -- "$FILE") | |
fixups+="$REF $FILE"$'\n' | |
done | |
# consolidate fixups of same ref to one fixup commit | |
commits=$(echo "$fixups" | sort | sed 1d | awk 'BEGIN {ORS=""} {if (LAST!=$1) print "\n"$1; print " "$2; LAST=$1}' | sed 1d) | |
while IFS= read -r LINE; do | |
REF=$(echo "$LINE" | awk '{print $1}') | |
FILES=$(echo "$LINE" | awk '{$1=""; print $0}') | |
echo "$FILES" | xargs git commit --fixup="$REF" -- | |
done <<< "$commits" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment