I’ve found that I use this little git-pattern quite often.

Full diff

Pure refactor

Actual change

Situation:

  • I’ve developed a feature, having made one commit (or multiple chronological ones)
  • The final result is good, but the diff is large and difficult to read

This is usually the case when some refactoring was needed, for example inlining/extracting, nesting/un-nesting etc.

Pattern:

  • git branch feature-backup Back up the current branch with the final state
  • git reset --hard master Restore current branch to master
  • Redo only the refactoring. git commit, with a message making it clear no business logic has changed
  • git reset feature-backup Restore the working directory to the wanted final state again
  • git commit with the actual feature

This allows me to create easy-to-review pull requests, improving the lives of my reviewers, even though the development process wasn’t this linear.