One PR - One Commit

Proposed solution for better GIT history

Palanivelrajan B

Sep 19, 2018

Current State

Meaningful Commits

Only 6 meaningful commits

Remaining commits are all noice adding no value

Typical PR commit history

Text

  • Branch created and merged in a day
  • Still has 3 merge commits
  • 1 real fix, but the changes are spread across 4 commits
  • If the PR takes time to merge, it gets bad

Current Problems

  • Git history is very complicated. Difficult to track when happened and when
  • Too many merge commits, creating no real value.
  • High traffic repo, so had to merge master into pullrequest branch multiple times
  • Difficult to see all the changes done in a repo to fix a particular OM ticket. The changes are spread across multiple commits
  • Makes it difficult to cherry pick and give a hot fix when needed

Another PR

  • Lot of review comments
  • Still managed to have no merge commits
  • He also managed to do all the changes in a single commit !
  • Isn't he an awesome developer ?

Another PR

Of course Palanivel is an awesome developer :)

Proposed Solution

Git Rebase

Git Rebase VS Git Merge

  • Sample repository with diverging branches
  • Feature branch is behind master

Git Merge

  • One flavor of merge. We merge feature into master
  • Creates a merge commit
  • If the feature is not developed fully, we merge master into feature which creates merge commit in the feature branch

Git Rebase

  • Replays all the commits done in the feature branch on the latest master commit
  • No merge commit
  • Cleaner git history

Original State

Git Rebase

  • Rebase rewrites git history
  • Do not do if multiple people are working on the same branch
  • Never do this on "master" or "priority" branches

Why should we use Rebase?

  • Majority of the time, a single developer owns a feature branch / Pull request
  • He commits multiple times during the course of the PR lifetime
  • Gets review commits and makes more changes
  • Master 99% of the time will get diverged,forcing him to merge from master , creating merge commit.
  • Thereby adding lot of noise to git history.

Precaution that we should take to support Rebase

  • Prevent force push to master and priority branches. This can be done in bitbucket
  • Educate our developers to understand merge vs rebase master. A lot of material available online. This is a hot topic in git community.

DEMO

Proposal Summary

  • Starting doing rebase instead of merge for all PR's
  • Combine code changes, review commits into one (preferred) or more meaningful commits. This can be done by git interactive rebase
  • PR reviewers enforce this to all the new PR's created.
Made with Slides.com