That's a "fixup". It is not a one click solution, but it is just 2 commands. Basically, you commit the change using
git commit --fixup=<commit that should have included this change> ...
and this new commit will have a marker with a comment that starts with fixup! ...
.
Then do a
git rebase -i --autosquash
and the rebase will automatically setup the rebase instructions so the fixup commit is move to right after the target commit and marked as 'fixup' so that the rebase will collapse the two commits together.
One nice thing is that you can wait to do the rebase/autosquash until later, so you can keep your focus on your current work. You can even collect up a few and autosquash them all at once.
If you often forget the --autosquash
option, you can set it automatically
git config rebase.autosquash true
but @torek notes there are recent bug fixes to the autosquash feature and he recommends caution about using rebase.autosquash unless you use at least 1.7.10.5 or 1.8.4.
===
git commit --fixup:
--fixup=<commit>
Construct a commit message for use with rebase --autosquash.
The commit message will be the subject line from the specified
commit with a prefix of "fixup! ". See git-rebase(1) for details.
--squash=<commit>
Construct a commit message for use with rebase --autosquash.
The commit message subject line is taken from the specified commit
with a prefix of "squash! ". Can be used with additional commit
message options (-m/-c/-C/-F). See git-rebase(1) for details.
git rebase -i --autosquash
--autosquash
--no-autosquash
When the commit log message begins with "squash! ..."
(or "fixup! ..."), and there is a commit whose title
begins with the same ..., automatically modify the todo
list of rebase -i so that the commit marked for squashing
comes right after the commit to be modified, and change
the action of the moved commit from pick to squash (or fixup).
Ignores subsequent "fixup! " or "squash! " after the first,
in case you referred to an earlier fixup/squash with git
commit --fixup/--squash.