Quickly formatting a stack of commits
source link: https://blog.waleedkhan.name/formatting-a-commit-stack/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Quickly formatting a stack of commits
Apr 11, 2023
Czytaj po polsku 🇵🇱
CommentIntended audience: software engineers working with Git who use “patch stacks”/”stacked diffs”, such as how Git is used for the Git and Linux projects, as well as for many companies practicing trunk-based development; but not Git users who think the Git commit graph should reflect the actual development process.
CommentA 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.)
Commentgit-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
.
CommentHere’s a demo of formatting the commits in a stack (skip to 0:35 to see just the demonstration of git test fix
):
CommentI usually set git fmt
to an alias for something like
git test run --exec 'cargo fmt --all' --strategy worktree --jobs 8
Comments
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK