Quickly formatting a stack of commits
Intended audience |
|
Origin | My work on git-branchless. |
Mood | Unheeded by most. |
A certain category of developer uses Git with a “patch stack” workflow, in which they accumulate a sequence of small, individually-reviewable commits that together implement a large change. In these cases, it’s oftentimes useful to run linters or formatters on each commit in the stack and apply the results. However, this can be tedious, and a naive approach can cause needless merge conflicts. (One workaround is to run formatters on each commit in the stack backwards.)
git-branchless’s git test
command offers a solution to quickly run formatters, etc., on an entire stack of commits without causing merge conflicts. Additionally, it can be performed in parallel, and it caches results so that reformats of the same commits are skipped. You can see the announcement post or the documentation for git test
.
Here’s a demo of formatting the commits in a stack (skip to 0:35 to see just the demonstration of git test fix
):
I usually set git fmt
to an alias for something like
git test run --exec 'cargo fmt --all' --strategy worktree --jobs 8