< Commit rules
# incorrect
git commit -m "Fixed bug with Y"
git commit -m "Changing behavior of X"
git commit -m "More fixes for broken stuff"
git commit -m "Sweet new API methods"# correct
git commit -m "Refactor subsystem X for readability"
git commit -m "Update getting started documentation"
git commit -m "Remove deprecated methods"
git commit -m "Release version 1.0.0"# incorrect (> 50 chars)
git commit -m "Add NEW_WALLET action to global action file and add NEW_WALLET action creator"# correct
git commit -m "Add NEW_WALLET action and action creator"# incorrect
git commit -m "accelerate to 88 miles per hour"# correct
git commit -m "Accelerate to 88 miles per hour"# incorrect
git commit -m "Open the pod bay doors."# correct
git commit -m "Open the pod bay doors"# incorrect
git commit -m "Decrease time to send transaction
This pull request moves the http request to after signing and sending
transactions.
"# correct
git commit -m "Decrease time to send transaction
The core makes an http request prior to sending each transaction. It
then waits for the return of this request before sending the
transaction. This request took several seconds and is not required to
to complete before sending the transaction.
Moving the request until after the transaction is sent decreases
the time the use spends waiting to send a transaction.
"# incorrect
git commit -m "Derezz the master control program
MCP turned out to be evil and had become intent on world domination.
This commit throws Tron's disc into MCP (causing its deresolution)
and turns it back into a chess game."# correct
git commit -m "Derezz the master control program
MCP turned out to be evil and had become intent on world domination.
This commit throws Tron's disc into MCP (causing its deresolution)
and turns it back into a chess game."# incorrect (does not wrap at 72 chars)
git commit -m "Simplify serialize.h's exception handling
Remove the 'state' and 'exceptmask' from serialize.h's stream implementations, as well as related methods.
As exceptmask always included 'failbit', and setstate was always called with bits = failbit, all it did was immediately raise an exception. Get rid of those variables, and replace the setstate with direct exception throwing (which also removes some dead code)."# correct
git commit -m "Simplify serialize.h's exception handling
Remove the 'state' and 'exceptmask' from serialize.h's stream
implementations, as well as related methods.
As exceptmask always included 'failbit', and setstate was always
called with bits = failbit, all it did was immediately raise an
exception. Get rid of those variables, and replace the setstate
with direct exception throwing (which also removes some dead
code)."source: How to Write a Git Commit Message
Since open-source work is self-directed, there is no promise that anybody will want your work. Therefore, you need to work hard to convince the maintainers that your stuff is a good idea.
- Every commit should improve the code in some obvious way.
- Each commit should be stand-alone. They might want some and not others.
- No commit should break the program - all tests should pass, and all code should make sense at each point.
If you mess up, do not create another commit to fix it! Go back & repair the original commit, so that original commit will be desirable.
Put your commits in some sort of logical order, for example:
- Delete dead code & perform simplications
- Add new type definitions & helper components
- Implement the feature
- Remove old code that was replaced
Renaming files or variables should always happen in their own commits, separate from any code changes.
When working on a feature that is not yet complete, you may use "WIP" as a prefix in the commit message:
# acceptable for incomplete work
git commit -m "WIP Theme server in Settings"However, WIP commits should be cleaned up before creating a pull request. Use interactive rebase to either:
- Complete the work and update the commit message
- Split the WIP commit into logical, complete commits
- Remove the WIP prefix once the work is complete
WIP commits are useful for saving progress but should not be included in pull requests unless the PR is explicitly marked as a draft for early feedback.
- Avoid doing something just to undo it a few commits later.
- The repo should build and be free of all mistakes after every commit.
- Each commit should be useful on its own if we had to cherry-pick it.
Rebasing is your best friend when preparing your work for review. Your workflow can remain somewhat messy and disorganized to get the job done, however before you create a pull request for your work to be reviewed, you should interactively rebase (git rebase -i) to:
- Splitting: Separating unrelated changes in a commit
- Squashing: Join related commits together
- Reordering: Change the order of commits
See Git - Rewritting History for a guide on how to accomplish these edits to your branch. Or, read the summary below.
One commit makes 2 unrelated changes! How to split it?
If it’s simple:
- Stop the rebase right before the commit that needs splitting.
- Re-do and commit the first half of the changes.
- Continue rebasing.
If it’s complex:
- Use the “e” command to stop at the commit we need to split.
- Create an “anitmatter” commit that un-does half the changes.
- Revert the “antimatter” commit - this gives a clean commit that makes the changes.
- Do another rebase to join the original commit & antimatter commits.
- Use the "fixup" or "f" command to join two commits keeping the first commit message
- Use the "squash" or "s" command to join two commits and edit the commit message
- Use “fixup!” “squash!” in your commit message and add
--autosquashto your rebase command to tell git to automatically use these commands in your rebase.
- Use the "edit" or "e" command to edit commits. You can make small ammendments (
git commit --amend), edit commit messages, etc. - Make sure to run
yarn precommit && git rebase --continuebefore commiting changes. - You can even create whole new commits in this mode (omit
--amend!