
I recently happened upon an article by Julia Evans on what can go wrong when rebasing in Git. This made me realise that I should probably talk about my favourite, yet obscure, Git feature.
When using commit
you can use --fixup
<commitid> or --squash
<commitid> to create a commit that can be automatically fixup’d or squashed on the next rebase
with --autosquash
. This is handy, but you need to know the commitid
beforehand.
There is a type of refspec
that can resolve a regular expression to the commitid
of a matching commit: :/<RegExp>
. This will find the ID of the most recent commit (not necessarily on your current branch) with message matching /<RegExp>/
, and resolve to that.
It’s a killer feature with --fixup
and --squash
: in a pinch, you can create fixes to past commits that
- you only vaguely remember the message of, and
- Git can automatically move (autosquash) in the next interactive rebase.