-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write commit messages for humans #735
Open
nickcharlton
wants to merge
1
commit into
main
Choose a base branch
from
nc-write-commit-messages-for-humans
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't mind those prefixes, since it gives me context as a scan through the commit history.
What I find most valuable (and what I think you are proposing) is that each commit explains the why, and not the what. This might relate to #734.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's all about being purposeful with how you go about your changes, which is why I ended up doing this right after #734.
Does prefixing your commits provide value for other humans? If we're doing that consistently throughout a repository, go ahead. Otherwise consider if it's better to express yourself in a more human way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it can, but there's a nuance to it. For example, the last two PR's I closed were prefixed with "Rails", which I think was beneficial.
On client work, I also prefix commits with "Feature Name:" to give added context.
That being said, those are not Git patterns. I think I'm just getting hung up on the prefix part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😃
Along those lines, there's a common pattern that I see followed often in Go where you highlight the area of code changed in your commits. Now, I think this is likely something that's come from using monorepos (a different topic, but something else I think is a horrible idea) where that's much more meaningful. But, I've seen people follow the same pattern where you mention the file, or sub-directory or equivalent. You don't need to do that! It's in the
diff
!I went for a walk earlier and I thought that another side of this would be: if you're going to follow a specific pattern you should be linting for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I often follow the conventional commit format (https://www.conventionalcommits.org/en/v1.0.0/#summary) and I usually find prefixing commits to be highly valuable.
prefixing and following a standard format facilitates a level of cognitive funneling. When a commit is prefixed with a
type
, a human searching through the history can make a quicker judgement call if the commit is relevant to what they're looking for. If they're looking for new features, they look for thefeat:
prefixes. If it's a bug fix thenfix:
. The format<type>[optional scope]: <description>
lays out information so that as you read it, you are presented the broadest level of details first and the most narrow and specific last. Including scopes helps with this even more. If what I'm searching for doesn't fit the type or scope, then I don't even have to read the description.Knowing I need to tag and scope my commit message can also encourage me to keep my commits smaller and more atomic. I shouldn't fix a bug, develop a feature, modify CI config, update docs, add tests, fix style and refactor all in one commit because each of those have their own type tag and I can make granular commits for each of them. Also, if I get carried away making too many changes without committing, the format then encourages me to break up my work into smaller commits to write a commit message that conforms to the format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some examples:
style
type prefix at first because I wasn't adding new content, but working on style and layoutrefactor
to show I committed some reworkfix
to show I was addressing a linting issue. Which on a code project could bestyle
, but the exact mapping of types isn't consequential; it's important that in any one context everyone uses them the same way (a ubiquitous language if you will).feat:
)style:
build:
style
commits, one for each rule, all scoped tomarkdown
more references:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addendum — I've focused more on the human aspects above due to the conversation, but following a standard commit structure is also useful for automation and tooling (for example: automating the generation of CHANGELOGs). Though this can again be reconnected to the human aspect, if you have a standard set of tokens/slugs/prefixes in your commits, then a human can more easily use command line tools to filter the git history