Skip to content

Commit abe0d65

Browse files
author
Ben Goshow
committed
docs: Add language about commit history curation
1 parent 666adf6 commit abe0d65

1 file changed

Lines changed: 60 additions & 44 deletions

File tree

code-style/git/README.md

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,52 @@
22

33
![Git plus GitHub](http://i.imgur.com/R1imkCJ.png)
44

5-
We use Git version control for all of our projects at [Sparkbox][]. We host
5+
We use Git version control for all of our projects at [Sparkbox]. We host
66
our code on GitHub. Large features get their own branch and are merged with a
77
pull request by a person _other_ than yourself.
88

9-
109
## The Sparkbox Git Flow
1110

1211
Every place you work will have a different Git flow. At Sparkbox the Git flow is as follows:
1312

14-
1. [Create a branch][] off of master to fix an issue assigned to you.
13+
1. [Create a branch] off of master to fix an issue assigned to you.
14+
15+
1. Push this branch up to GitHub, and create a [pull request] when you are ready.
1516

16-
1. Push this branch up to GitHub, and create a pull request when you are ready.
17+
- Protip: Sometimes we create pull requests early as a place to collaborate on a solution. Consider opening a [Draft PR] to prevent your PR from accidentally being merged. You may also consider labeling these PRs as "DO NOT MERGE" or "WIP".
1718

18-
- Protip: Sometimes we create pull requests early as a place to collaborate on a solution. Consider labeling these as `DO NOT MERGE` or `WIP`. You might also utilize [Draft PRs][].
19+
1. To make the pull request process more consistent, your project might include a [pull request template]. An [example PR template] is included in the Standard as a starting point. There is also an [example issue template].
1920

20-
1. To make the pull request process more consistent, your project might include a [pull request template][]. An [example PR template][] is included in the Standard as a starting point. There is also an [example issue template][].
21+
1. Assign a reviewer to your pull request. Leave some nice documentation or even a [screencast](https://viewedit.com/) to give your reviewer a bit more background about the code you wrote in this pull request (include information about any interesting or difficult code, and where the reviewer can see the code that you are referencing). It can also be very helpful to include some instructions in the description of your pull request about how to test the changes you've made to the code.
2122

22-
1. Assign a reviewer to your pull request. Leave some nice documentation or even a [screencast](https://viewedit.com/) to give your reviewer a bit more background about the code you wrote in this pull request (include information about any interesting or difficult code, and where the reviewer can see the code that you are referencing). It can also be very helpful to include some instructions in the description of your pull request about how to test the changes you've made to the code.
23+
- Protip: Use interactive rebasing to [curate your commit history] before requesting a review. Squashing, reordering or rewording your commits will help [onboard the reviewer to your pull request][foundry_curated_commits].
2324

2425
1. The reviewer might ask you to [rebase off master](#Rebasing-a-Branch-onto-the-Master-Branch) if the branch has gotten behind master.
2526

2627
1. Your reviewer will either approve or request changes on your pull request.
27-
- If they request changes, please implement or further discuss their comments with them.
28+
29+
- If they request changes, please implement or further discuss their comments with them.
30+
- If no more changes to your code are needed, this will likely be a good time to ["squash your commits"][curate your commit history] before the reviewer merges them back into the main branch.
2831

2932
1. If your reviewer approves your pull request, they will fast-forward merge your branch into master using the CLI.
3033

31-
```cli
32-
git merge --ff-only <branch-name>
33-
```
34+
```cli
35+
git merge --ff-only <branch-name>
36+
```
3437

3538
1. The reviewer will then let you know your changes have been merged so you can move your Jira card.
3639

3740
1. Once the PR is merged, the reviewer deletes the branch.
3841

39-
4042
## Naming Branches
4143

4244
Consistent branch naming can help with team communication. A branch name might be the first peek a reviewer gets at what the work is related to. We use types (feat, fix, docs, etc.) to group our branch names so that we know what part of our workflow the branch belongs to, and a brief subject to describe what the branch does.
4345

4446
`feat--onUrlChange-event`
4547

4648
### Allowed Values for Types
47-
There are several types allowed to prefix branches and commits.
49+
50+
Sparkbox follows the [Conventional Commits] specification. There are several types allowed to prefix branches and commits.
4851

4952
- **feat** (new feature)
5053
- **fix** (bug fix)
@@ -65,6 +68,7 @@ Subjects need to be short, but descriptive. Multi-word subjects are separated by
6568
### Branches with Multi-type Commits
6669

6770
Even though our branches tend to be named similarly to our commit style, it's ok if you're working on a bug fix branch `fix--` and include other types of commits. For example, maybe you have a branch named `fix--unit-tests-IE9`, but you've done some `refactor`ing and made some `style` adjustments. Your commit messages for the branch might include:
71+
6872
```
6973
fix: unit tests for IE9
7074
@@ -81,15 +85,14 @@ It's totally ok to include all of those commits on your bug fix branch. You migh
8185

8286
If you identify any of these concerns in your branch, it's worth exploring whether all the work you're doing should be reviewed together. Sometimes work does need to be all together, but in a lot of cases we can [break up that work](https://www.netlify.com/blog/2020/03/31/how-to-scope-down-prs/) to make it easier for our code reviewers to provide a thorough review.
8387

84-
8588
## The Art of the Commit Message
8689

8790
We use a strict writing style for all of our commit messages. The style we use helps ensure that our commits stay small and are easy to browse.
8891

89-
_Never forget all this juicy knowledge! Set your commit message template to
92+
_Never forget all this juicy knowledge! Set your commit message template to
9093
[this wonderful example](./.gitmessage), by running:_
9194

92-
```git config --global commit.template "path/to/.gitmessage"```
95+
`git config --global commit.template "path/to/.gitmessage"`
9396

9497
### The Layout
9598

@@ -105,10 +108,11 @@ _Never forget all this juicy knowledge! Set your commit message template to
105108

106109
The subject consists of the `<type>` and the `<subject>`.
107110

108-
> Protip: Find yourself with an _and_ in that commit title? Consider breaking
109-
> the commit down. `git commit -p` is your friend!
111+
> Protip: Find yourself with an _and_ in that commit title? Consider breaking
112+
> the commit down. `git commit -p` is your friend!
110113
111114
#### Allowed Types
115+
112116
Find the [allowed types above](#Allowed-Values-for-Types).
113117

114118
- **feat**
@@ -121,25 +125,26 @@ _changes_.
121125

122126
### Funtip
123127

124-
Work hard, play hard! Consider prefixing your commit messages with a relevant emoji.
125-
126-
* :art: `:art:` when improving the format/structure of the code
127-
* :racehorse: `:racehorse:` when improving performance
128-
* :non-potable_water: `:non-potable_water:` when plugging memory leaks
129-
* :memo: `:memo:` when writing docs
130-
* :penguin: `:penguin:` when fixing something on Linux
131-
* :apple: `:apple:` when fixing something on macOS
132-
* :checkered_flag: `:checkered_flag:` when fixing something on Windows
133-
* :bug: `:bug:` when fixing a bug
134-
* :fire: `:fire:` when removing code or files
135-
* :green_heart: `:green_heart:` when fixing the CI build
136-
* :white_check_mark: `:white_check_mark:` when adding tests
137-
* :lock: `:lock:` when dealing with security
138-
* :arrow_up: `:arrow_up:` when upgrading dependencies
139-
* :arrow_down: `:arrow_down:` when downgrading dependencies
140-
* :shirt: `:shirt:` when removing linter warnings
128+
Work hard, play hard! Consider prefixing your commit messages with a relevant emoji.
129+
130+
- :art: `:art:` when improving the format/structure of the code
131+
- :racehorse: `:racehorse:` when improving performance
132+
- :non-potable_water: `:non-potable_water:` when plugging memory leaks
133+
- :memo: `:memo:` when writing docs
134+
- :penguin: `:penguin:` when fixing something on Linux
135+
- :apple: `:apple:` when fixing something on macOS
136+
- :checkered_flag: `:checkered_flag:` when fixing something on Windows
137+
- :bug: `:bug:` when fixing a bug
138+
- :fire: `:fire:` when removing code or files
139+
- :green_heart: `:green_heart:` when fixing the CI build
140+
- :white_check_mark: `:white_check_mark:` when adding tests
141+
- :lock: `:lock:` when dealing with security
142+
- :arrow_up: `:arrow_up:` when upgrading dependencies
143+
- :arrow_down: `:arrow_down:` when downgrading dependencies
144+
- :shirt: `:shirt:` when removing linter warnings
141145

142146
Example:
147+
143148
```
144149
:fire: refactor: removed unused container elements
145150
```
@@ -150,7 +155,7 @@ The body of the commit message should use a style similar to the one proposed
150155
in this [article by tpope][tpope]. The body, just like the subject, should use
151156
an imperative tone.
152157

153-
Another nice thing you can do in the body of your commit is to state what the `issue` is that you worked on, and what your code changes and `fix` entailed. The `fix`, or the _why_ of your code is really interesting, as well as important, and helps others understand the solution you chose.
158+
Another nice thing you can do in the body of your commit is to state what the `issue` is that you worked on, and what your code changes and `fix` entailed. The `fix`, or the _why_ of your code is really interesting, as well as important, and helps others understand the solution you chose.
154159

155160
Example:
156161

@@ -270,16 +275,23 @@ scope: {
270275
The removed `inject` wasn't generally useful for directives so there should be no code using it.
271276
```
272277

278+
## Curating Your Commit History
279+
280+
There are a number of reasons why you may want to "rewrite" the history of your work.
281+
282+
**Before requesting a review of your work**, you may want to clean up your commit history to better "tell the story" of what you did. Using interactive rebasing, you can curate your commit history to combine (squash or fixup), reorder, or reword your commits to better [onboard the reviewer to your pull request][foundry_curated_commits].
283+
284+
**After your work has been approved**, there is no longer a need to preserve every step of your process for the record. Of course, your code changes must be preserved, but when merging them back into the main branch it's more important to communicate the high-level reasoning for the overall PR. This makes the flow of changes to the main branch more easily digestible for later viewers. Once again, you will use interactive rebasing to combine all of your changes into 1 or 2 commits, communicating notable changes in the body of the commit message. This is often referred to as "squashing your commits."
273285

274286
## Rebasing a Branch onto the Master Branch
275287

276-
Rather than merging commits from another branch into the master branch, Sparkbox prefers to rebase commits on top of the master branch. One of the best reasons for why Sparkbox does this is that rebasing creates a very clear and clean commit history, free of "Merged branch `other-branch`" commits (which can muddy up the history). To learn a bit more about why rebasing is preferred over merging at Sparkbox, read Ryan Cromwell's post on [Taking Control of Your Commit History](https://seesparkbox.com/foundry/take_control_of_your_commit_history). Additionally, here is a diagram that depicts the differences between merging and rebasing:
288+
Rather than merging commits from another branch into the master branch, Sparkbox prefers to rebase commits on top of the master branch. One of the best reasons for why Sparkbox does this is that rebasing creates a very clear and clean commit history, free of "Merged branch `other-branch`" commits (which can muddy up the history). To learn a bit more about why rebasing is preferred over merging at Sparkbox, read Ryan Cromwell's post on [Taking Control of Your Commit History]. Additionally, here is a diagram that depicts the differences between merging and rebasing:
277289

278290
![Merging](merge.png)
279291

280292
![Rebasing](rebase.png)
281293

282-
For the purposes of this example explaining rebasing, let's say that the branch you need to rebase is called `chore-teaching-example`, and that this branch has gone through all of the Git flow discussed above for a pull request. Follow these next steps to rebase a branch onto master:
294+
For the purposes of this example explaining rebasing, let's say that the branch you need to rebase is called `chore-teaching-example`, and that this branch has gone through all of the Git flow discussed above for a pull request. Follow these next steps to rebase a branch onto master:
283295

284296
1. Open your terminal and checkout the branch to be rebased: `git checkout chore-teaching-example`.
285297

@@ -291,10 +303,11 @@ For the purposes of this example explaining rebasing, let's say that the branch
291303

292304
1. If your branch is behind the master branch's commits, run `git rebase origin/master`. You can also run `git rebase origin/master -i` which will allow you to _interactively_ (that's where the `-i` comes from) select which commits you want to be added to the master branch, and also permit you to squash commits and reword commit messages. If your branch is already rebased, you can skip to step 7.
293305

294-
- Upon rebasing, you may run into merge conflicts. Follow the helpful instructions offered by Git in your terminal, and fix all of the merge conflicts until you have rebased your branch on top of master.
306+
- Upon rebasing, you may run into merge conflicts. Follow the helpful instructions offered by Git in your terminal, and fix all of the merge conflicts until you have rebased your branch on top of master.
295307

296308
1. After rebasing your branch on top of the master branch, you'll need to force push these changes to your GitHub version of the branch. Run `git push origin chore-teaching-example --force-with-lease`.
297-
- Make sure any and all tests that run when you push your branch to GitHub succeed (this may include Circle CI, or Code Climate tests).
309+
310+
- Make sure any and all tests that run when you push your branch to GitHub succeed (this may include Circle CI, or Code Climate tests).
298311

299312
1. When you have made sure that your newly rebased branch did not break any tests on GitHub, you can checkout the master branch in your terminal by running: `git checkout master` and `git pull origin master` to grab any new changes to the master branch that you might not have.
300313

@@ -304,8 +317,8 @@ For the purposes of this example explaining rebasing, let's say that the branch
304317

305318
Voila! You're done. You've successfully rebased a branch onto the master branch!
306319

307-
308320
## Additional Resources
321+
309322
- [GitHub Pull Requests for Everyone](https://seesparkbox.com/foundry/github_pull_requests_for_everyone) by Catherine Meade
310323
- [Give Better Pull Requests With Screencasts](https://seesparkbox.com/foundry/give_better_pull_requests_with_screencasts) by Ethan Muller
311324
- [Stop Giving Depressing Code Reviews](https://seesparkbox.com/foundry/stop_giving_depressing_code_reviews) by Bryan Braun
@@ -319,11 +332,14 @@ Voila! You're done. You've successfully rebased a branch onto the master branch!
319332
[karmac]: http://karma-runner.github.io/0.8/dev/git-commit-msg.html
320333
[365]: http://365git.tumblr.com/post/3308646748/writing-git-commit-messages
321334
[tpope]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
322-
[Draft PRs]: https://github.blog/2019-02-14-introducing-draft-pull-requests/
323-
[pull_request]: https://help.github.com/articles/using-pull-requests
335+
[Draft PR]: https://github.blog/2019-02-14-introducing-draft-pull-requests/
336+
[pull request]: https://help.github.com/articles/using-pull-requests
324337
[Sparkbox]: http://seesparkbox.com
325-
[Sprintly]: https://sprint.ly/
326338
[pull request template]: https://seesparkbox.com/foundry/better_pull_requests_merge_requests_with_templates
327339
[example PR template]: ./PULL_REQUEST_TEMPLATE.md
328340
[example issue template]: ./ISSUE_TEMPLATE.md
329341
[Create a branch]: #naming-branches
342+
[curate your commit history]: #curating-your-commit-history
343+
[Conventional Commits]: https://www.conventionalcommits.org/en/v1.0.0/
344+
[Taking Control of your Commit History]: https://seesparkbox.com/foundry/take_control_of_your_commit_history
345+
[foundry_curated_commits]: https://sparkbox.com/foundry/interactive_rebasing_curates_commits_to_speed_up_pull_request_review_process

0 commit comments

Comments
 (0)