Assuming you have fzf installed. Tested on Ubuntu 20.04.
Adapted from https://twitter.com/ericniebler/status/1789843284027728166 and https://twitter.com/foonathan/status/1789943474994745494
This is helpful in a situation where you mean to ammend a commit back in history (not the last one, for that one you can just git commit --amend
).
After staging some changes:
- This opens a fzf picker to select the commit you want to amend with your changes, with a preview pane that shows the commit detail when you select one
- This
git commit --fixup=<commit>
- see git docs for --fixup
- This new
fixup!
will be automatically squashed with the target commit during the rebase below
- This performs a
git rebase --update-refs --autosquash -i <commit_before>
--autosquash
squashes thefixup!
commit--update-refs
: Automatically force-update any branches that point to commits that are being rebased
fixup, simpler