Skip to content

Working with commits

David Manners edited this page Jun 14, 2019 · 5 revisions

Formatting commit messages

While providing your contribution to the Magento code base it is important to accompany it with a meaningful commit message. A meaningful commit message is important to:

  • Help speed up the reviewing process
  • Help us write a good release note
  • Help future developers understand why a particular change was made

We recommend including the GitHub issue number and title, as well as some additional comments that you feel are relevant. Adding the GitHub issue, your commit is automatically linked to this issue. Everyone can quickly see your committed work and the issue associated to it in GitHub.

magento/magento2#<issue-number>: <issue-title>
- <additional comment>

For example:

magento/magento2#8618: Apply coupon code button issue on checkout
- fixed issue with assigning coupon_code value from totals

Squashing commits

During the development or review process you, or a reviewer, may feel like the amount of commits you have is too much or that some commits would work better as one single commit. It is possible using git to squash or edit your commits after making them. To do this you will need to use a git command called "rebase".

For example if you would like to squash the last 3 commits into 1 commit the command you would run would be:

$ git rebase -i HEAD~3

This would then give you a prompt with the following information

pick f7f3f6d a few file changes
pick 310154e some file changes
pick a5f4a0d file changes

# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

To squash these commits into 1 you will need to make the following changes:

pick f7f3f6d a few file changes
squash 310154e some file changes
squash a5f4a0d file changes

Once you save and exit the editor git will use the picked commit as the basis and squash the next two commits into it. You can do more than just squash commits with the rebase tool. For more information see the git documentation on Rewriting History.

Tips on commits

  • If it feels hard to summarize what your commit is, then try splitting it into multiple commits.
  • If there is no GitHub issue, you can skip adding magento/magento2#<issue-number>: and just add a meaningful title.
  • If you are working on a community project, please update the issue part as appropriate. For example, Import Export work should be magento-engcom/import-export-improvements#<issue-number>:.