Always review your changes

In yesterday's email where I wrote about git stash, I mentioned the -p or --patch options.

When stashing changes, this allows you to interactively select which changes you want to stash and what you don't.

This is supported by other Git commands, including git add.

I always use git add -p when adding changes as it gives me the chance to review them before committing them.

If I left any stray comments, debug code, trailing spaces or anything I don't want to commit, I can remove them.

If I was working on multiple changes (which I avoid), I can select the appropriate changes and create commits related to each change to keep the history clean and useful.

I also use git diff and git diff --staged to review changes as well as git show to review commits.

By doing this, I know my commits will be in the best state for others to review now or for me to review if I need to in the future.

- Oliver

Was this interesting?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an Acquia-certified Drupal Triple Expert with 17 years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.