One of the challenges I found in creating better commits is that I often had other changes in my files. Running
git add . (or my preferred
git add -u) resulted in unrelated changes being introduced in my commit.
Then I learned about
git add -p.
Using git add --patch (or the short version
git add -p) prompts you for each section of changes (a.k.a. hunks), which you can either stage for your commit (
y) or skip for now (
n to be included in a later commit).
Reviewing Your Changes Before Commits
From the Command Line
git diff --staged
will show you all the changes that are currently staged. I think of this as a preview of the commit I’m about to create.
As a Preview in Your Editor
You can modify your Git configuration so that whenever you author a commit in your editor you can also see a preview of the changes that go with that commit. See how to Preview Your Changes When Writing Your Commit Message.