'git inject' is a git alias (see code at the bottom). It is similar to 'git
commit --amend', but it allows you to 'inject' your changes into commits further back in history (using 'rebase').
If you're as pedantic as I am about the git history you're about to push into master (as far as I can control it, I strive to keep each commit conceptually coherent), you'll often come to a situation where you have a modification that really belongs in an older commit. It takes a few git commands to stash other changes away, commit the modification, then interactively rebase over some previous commit, move your commit into place, change to 'fixup', save, exit, and then unstash whatever else you had lying around. Not fun.
Here's how 'git inject' makes it fun:
>> git inject <commit-ref> <patch-ref>
>> git inject HEAD^^ -a # inject all work-dir modifications
>> git inject a28kd8 -p # interactively select patches to inject
>> git inject HEAD~4 file1 # inject the modifications in file1
Just put this into your .gitconfig under 'aliases':
inject = "!f() { set -e; HASH=`git show $1 --pretty=format:\"%H\" -q`; shift; git commit -m \"fixup! $HASH\" $*; [ -n \"$(git diff-files)\" ] && git stash && DIRTY=1; git rebase $HASH^^ -i --autosquash; [ -n \"$DIRTY\" ] && git stash pop;}; f"
It wasn't immediately obvious to me that you can also re-order patches using `rebase -i`. I've used for squashing and dropping temporary code before but realizing it can also reorder commits was really useful.