Maintain a Clean Commit History
Learn to commit only what’s relevant and clean the rest of the changes.
We'll cover the following
Before we commit, we may want to clean the commit to only keep what’s relevant.
The git add
workflow
Here’s a typical git add
workflow that contains a reveal and double-check process to ensure that only the changes we want to commit are added.
-
Run
git status
to see what has changed since the last commit. Review the list to check if all changes are for the same purpose. -
Run
git add .
if all the changes are for one purpose. Otherwise, rungit add <folder/file>
to separate different files/folders into different commits according to their purpose. -
Run
git status
to reveal the added (staged) changes. These are the changes that will be committed. -
Run
git commit -m
to commit the change with a one-line comment. Or rungit commit
and write a long message if it’s a crucial commit. -
Repeat the steps 1 through 4 until all changes are committed.
Get hands-on with 1400+ tech skills courses.