git commit -m "…
Cloud Portal Services, EMC
2016 February 4
Kurt MacDonald
Manager, Core Experience Team
Software
Development
Cycle
- Requirements
- Whiteboard Design Sessions
- Feature Development
- Documenting Code
- Style Guides
- Automated Tools
- Unit Tests
- Integration Tests
- Source Code Management
- Code Reviews
- QA
- Code Demonstration
- Code Reading
- “Tech Talk” Presentations
- Post-mortem
Software
Development
Cycle
- Requirements
- Whiteboard Design Sessions
- Feature Development
- Documenting Code
- Style Guides
- Automated Tools
- Unit Tests
- Integration Tests
-
Source Code Management
- Write Useful Commit Messages
- Code Reviews
- QA
- Code Demonstration
- Code Reading
- “Tech Talk” Presentations
- Post-mortem
Culture
We do this stuff and encourage others to do it because of who we are as individuals and as a team.
Process
We follow these steps because they enable our organization to deliver consistent results.
Quotes from Coworkers
“If there is too much overhead/frustration, then you will not do it.”
“No shame in bad code, shame in not fixing it (or publishing bad code).”
“All about people: easy to be passive aggressive. Sometimes better to talk directly.”
“I think what we are looking for is really just the changes in clear english.”
“Writing good commit messages helps people know if they even need to look at the code.”
On commit messages
Btw, the commit message rules we use in the kernel really *are* objectively better. The fact that some other projects don't care that much is fine. But just compare kernel message logs to other projects, and I think you'll find that no, it's not just "my opinion". We do have standards, and the standards are there to make for better logs.

“Merge branch 'asdfasjkfdlas/alkdjf' into sdkjfls-final”
Capitalized, short (50 chars or less) summary
Fixes #1138 (Redmine) or CPS-1234 #resolve (Jira)
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body. The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.
Write your commit message in the present tense: "Fix bug" and not "Fixed
bug." This convention matches up with commit messages generated by
commands like git merge and git revert.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded by a
single space, with blank lines in between, but conventions vary here
- Use a hanging indent
Content And Format
- Terse summary of change first line: Max 50 characters.
- Capitalize and use imperative: “Fix the foo in bar to avoid baz”
-
Include issue reference on third line:
-
Jira Smart Commits: CPS-1234 #resolve
https://confluence.atlassian.com/fisheye/using-smart-commits-298976812.html -
Redmine: Fixes #1234
http://wiki.maginatics.com/dev/bugs?s[]=redmine
-
Jira Smart Commits: CPS-1234 #resolve
- Limit line length of body: ~72 chars so log fits most displays.
- Include details in body, high level changes: Markdown style.
- Write for: Your future self, Peers, QA, Documentation Writers.
Commit Message Format

Gerrit

Setup for Gerrit Workflow in Git
- Wiki
-
Global
git config --global user.email "my.name@mydomain.com"
git config --global user.name "My Name" -
Use 'commit-msg' hook to automatically add Change-Id for Gerrit
https://confluence.dpc.lab.emc.com/display/LT/Gerrit+commit-msg+hook
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Gerrit
Workflowin Git
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Create and switch to a new branch.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Show changes in the working directory.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Add changes to be committed by hunk.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Create a commit and commit message.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Push all commits in branch to Gerrit.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Add the new changes to be committed.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Include the changes in the last commit.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Push updated commit to Gerrit.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Add changes by hunk for updating commit.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Update commit w/o changing message.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Push updated commit to Gerrit.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Switch to master branch.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master
$ git log
# Repeat.Pull down the latest code from Gerrit.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master master
$ git log
# Repeat.Update master with latest code.
# Create a new branch for development.
$ git checkout -b newFeatureBranch
# Write some code.
$ git status
$ git add -p
$ git commit -m "Add foo
>
> Fixes #1138.
>
> Some additional details after one blank
> line that describe the changes."
$ git push origin HEAD:refs/for/master
# Make changes based on feedback.
$ git add -p
$ git commit --amend
$ git push origin HEAD:refs/for/master
# Make more changes based on comments.
$ git add -p
$ git commit --amend -C HEAD
$ git push origin HEAD:refs/for/master
# Move back to the master branch.
$ git checkout master
$ git fetch
$ git merge origin/master master
$ git log
# Repeat.List all the commits to review history.
Review Guidelines and Tips
Following the below guidelines to improve review quality and speed up the process:
Try to keep review requests small.
This makes the history clear and it can dramatically speed up response times from reviewers.
Try to split independent changes into different requests.
Changes that are logically separate should be split into separate commits.
Give feedback on reviewers’ comments
This could be as simple as a “Done” comment. This saves time for the reviewers in followup.
Constructive feedback is always welcome.
The goal is to improve the quality of our code.
1.
2.
3.
4.
Git Tips (1 of 3)
-
Never develop on the master branch;
always create a new branch before you start coding.
git checkout -b newbranchname - Show current branch in bash. (code-worrier.com/blog/git-branch-in-bash-prompt)
- Use Git tab completion. (git-scm.com/book/en/Git-Basics-Tips-and-Tricks)
- Commit messages can and should be more than 1 line. (tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
Git Tips (2 of 3)
-
Compare commits between 2 or more branches:
git show-branch origin/master master working -
Checkout the previous branch:
git checkout - -
Use “hunks” to create smaller commits: (bignerdranch.com/blog/using-git-hunks)
git add -p -
Show diff between last commit and staged changes:
git diff --staged -
Show all branches including remotes:
git branch -av -
View the last commit with diffs:
git show
Git Tips (3 of 3)
-
Closest thing to “undo” after `git commit --amend`:
git reset --soft HEAD@{1} -
Browse the history of a single file in Git:
git log --follow -p filename -
List branches from newest to oldest:
git for-each-ref --sort=-committerdate refs/heads/ -
Customize the display of Git log:
git log --pretty=oneline -10
git log --pretty=oneline --stat
git log --pretty=format:"[%h] %ae, %ar: %s" --stat
thank you
I welcome your questions, comments, and feedback.
Commit Messages
By zurt
Commit Messages
Commit messages talk at CPS Developer Conference on Thursday, February 4, 2016
- 491