You have decided that you would rather have your git log be concise and informative than a minute-by-minute log of everything you did. But your commit log still doesn't feel as useful as it should be. Some changes seem random or unrelated to the commit message it was introduced in. Squashing everything is a chore.
Git provides you with some features for creating great messages that will even tie into a gitlab feature.
Step zero
Setup your gitconfig with the following.
[alias]
fu = commit -a --fixup
fuh = commit -a --fixup HEAD
sq = commit -a --squash
sqh = commit -a --squash HEAD
squash = "!f() { git rebase -i --autosquash ${1:-master}; }; f"
Starting your work
Do some work and commit it with a message describing what the feature is.
When you make a decision or major change
Run git sqh
and provide a message explaining your decision or change.
When you need to push or make some trivial changes
Run git fuh
to commit without a message.
Multiple final commits
You may be working and need to make a change that is tangential to the feature and want to be considerate to future devs by splitting the work into multiple final commits. In this instance we will be using fu
and sq
.
git fu (commit)
git sq (commit)
When you are done with the feature
Run git squash
to clean up the commit history. You will first be presented with the interactive rebase prompt and you probably wont need to do anything and just save and exit the prompt. Then you will be presented with a final commit message with the initial commit message and all the squash messages you made before and you can use all that information to write an informative commit message for future developers.
Appendix
For more information read the documentation at man git-commit
and man git-rebase
.
Top comments (0)