Title: &#x27;git inject&#x27; is a git alias (see code at the bottom). It is similar to &#x27;git
commit --amend&#x27;, but it allows you to &#x27;inject&#x27; your changes into commits further back in history (using &#x27;rebase&#x27;).<p>If you&#x27;re as pedantic as I am about the git history you&#x27;re about to push into master (as far as I can control it, I strive to keep each commit conceptually coherent), you&#x27;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 &#x27;fixup&#x27;, save, exit, and then unstash whatever else you had lying around. Not fun.<p>Here&#x27;s how &#x27;git inject&#x27; makes it fun:<p>&gt;&gt; git inject &lt;commit-ref&gt; &lt;patch-ref&gt;<p>&gt;&gt; git inject HEAD^^ -a      # inject all work-dir modifications<p>&gt;&gt; git inject a28kd8 -p      # interactively select patches to inject<p>&gt;&gt; git inject HEAD~4 file1   # inject the modifications in file1<p>Just put this into your .gitconfig under &#x27;aliases&#x27;:<p>inject = &quot;!f() { set -e; HASH=`git show $1 --pretty=format:\&quot;%H\&quot; -q`; shift; git commit -m \&quot;fixup! $HASH\&quot; $*; [ -n \&quot;$(git diff-files)\&quot; ] &amp;&amp; git stash &amp;&amp; DIRTY=1; git rebase $HASH^^ -i --autosquash; [ -n \&quot;$DIRTY\&quot; ] &amp;&amp; git stash pop;}; f&quot;
Upvote: