A civic-minded citizen seeking the singularity

An entry

One Git commit from feature/branch to master

Date: 2015-01-30
Status: release
Tags: git

Using git, I sometimes sense pressure to make a meaningful, ever-lasting commit message. Am I using the appropriate level of detail when making commit messages? Is a WIP (Work in Progress) commit dirtying up git history? Any cognitive tension becomes a small friction to committing and sharing code.

Commit often, early, and freely in feature branches. Communicate with your team, and when it comes time to finalize a Pull Request, rest as ease, knowing you can cleanup your history with a clean diff of code.

Many developers I work with love to use rebase, and I've used it quite a bit myself. Though, I've also seen a handful of times where commits mysteriously vanish (due to team coordination and branch management, not due to any flaw of Git).

I'm starting to the following method a bit more when I'm ready to finalize a Pull Request from a feature branch that has several commits that I'd prefer to commit as one.

Generate a diff between 2 git branches

git diff branch_name_from branch_name_to --binary > name_of_diff.diff

Notice the use the --binary flag if you have files, like images or pdfs.

Then, create a new branch off of branch_name_from - for instance:

git checkout -b master new_branch_name

then with new_branch_name checked out, apply the diff

git apply name_of_diff.diff

Now, you'll have one clean commit, based on the diff between two branches.