A good commit message helps both you and your collaborators better understand your code. A series of good messages will create a well-documented history as your code evolves. This also makes it easier for someone to pick up where you left off.
The first line of a commit message is the summary AKA the title. This should be a summary of the commit which is 50 characters or less.
redirect
Redirect user to the requested page after login
After the summary, you should leave one blank line, then write a more detailed description of your commit. The description should be no longer than 72 columns in width. It should provide a detailed explanation of each change you made in the commit. Formatting your description with the bulleted list markdown is a great way visibility.
If your commit is resolving an issue on Github, this is a good place to reference the issue number. For example, if you are resolving issue 42, you could add Resolves #42
. If you copy this line into your pull request later, it will automatically close the issue when your PR is merged.
If your commit is lengthy (though you should strive for it to be short!) you can add helpful headers to separate the bullet points in your description. Headers like New features
, Clean up
, and TODO
are useful.
redirect on login
* Store requested path in a session variable
* Redirect to the stored location after successfully logging in the user
* Resolves #42
New features
* Store requested path in a session variable
* Redirect to the stored location after successfully logging in the user
* Resolves #42
Clean up
* Fixed indentation in the router
TODO
* Connect the back-end FTP capacitor
Here we combine the header and descriptions from earlier to give you an idea of the full commit message.
redirect
redirect on login
Redirect user to the requested page after login
* Store requested path in a session variable
* Redirect to the stored location after successfully logging in the user
* Resolves #42
Redirect user to the requested page after login
New features
* Store requested path in a session variable
* Redirect to the stored location after successfully logging in the user
* Resolves #42
Clean up
* Fixed indentation in the router
TODO
* Connect the back-end FTP capacitor
Our commits have to go somewhere, and that's where the branch comes in. Whenever we want to add a new feature to our project, we create a new branch (usually off of master.) For example, a good branch name for our previous commit would be fix-login-redirect
.
All commits on this feature branch should be related to fixing the login redirect issue. If we want to work on another feature, we can go back to our base and make another branch. For example, if we also notice an issue with the registration form, we would switch back to master
and make another branch fix-registration-form
.
When we are finished making commits on our feature branch, we need to open a pull request to have our changes merged in. The pull request should detail the changes we've made across various commits in our branch. Remembering everything we did on our branch can be difficult, but since we've been making good commit messages, our work is already done! All we need to do is copy our good commit messages into the PR, and add extra information where necessary. Add some nice markdown to format the pull request and we're good to go.
Remember we can reference and auto-close issues by adding a line like Resolves #42
. We can also provide a link to an individual commit by referencing its 7 character SHA (e.g. 48e15af
). In both cases, Github will automatically create links to the issue/commit for us.
Below are examples of well-formatted pull request using our commits from earlier. Don't forget to also add a descriptive title!
##### Redirect user to the requested page after login 48e15af
* Store requested path in a session variable
* Redirect to the stored location after successfully logging in the user
* Resolves #42
Redirect user to the requested page after login 48e15af
- Store requested path in a session variable
- Redirect to the stored location after successfully logging in the user
- Resolves #42
#### Redirect user to the requested page after login 48e15af
##### New features
* Store requested path in a session variable
* Redirect to the stored location after successfully logging in the user
* Resolves #42
##### Clean up
* Fixed indentation in the router
##### TODO
* Connect the back-end FTP capacitor
Redirect user to the requested page after login 48e15af
- Store requested path in a session variable
- Redirect to the stored location after successfully logging in the user
- Resolves #42
- Fixed indentation in the router
- Connect the back-end FTP capacitor
https://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message
👍