Skip to content

Instantly share code, notes, and snippets.

@peterberkenbosch
Created March 29, 2026 12:10
Show Gist options
  • Select an option

  • Save peterberkenbosch/4a9acd91f0e15030c68ccc99aff1a92e to your computer and use it in GitHub Desktop.

Select an option

Save peterberkenbosch/4a9acd91f0e15030c68ccc99aff1a92e to your computer and use it in GitHub Desktop.
Fixing a merge commit on master - restoring linear history

Fixing a Merge Commit on Master (Restoring Linear History)

The Problem

A merge commit landed on master, breaking the project's linear history requirement.

*   5fc5d7ecc Merge remote-tracking branch 'origin/develop'  (HEAD → master)
|\
| * 1172ababb fix: rescue PaymentError and render error from Stripe (#5469)
* | 5d617ca38 fix: rescue PaymentError and render error from Stripe (#5469)
|/
* 89e7d6eff fix: deduplicate accounting permissions when both V1 and V2 are enabled (#5468)

Two copies of PR #5469 exist — one on each branch — with identical content but different SHAs. The merge commit (5fc5d7ecc) joined them, creating a non-linear fork.

Root Cause

Someone ran git merge origin/develop on master instead of git rebase. This created a merge commit that joins two parallel histories.

The Fix

We want master to point at the same commit as develop's version of the history (1172ababb), which is already linear. Since develop is ahead of master (has commits #5471 and #5472), we reset master to its latest commit.

Step 1: Verify the situation

# Confirm the merge commit exists
git log --oneline --graph origin/master -5

# Confirm develop has a clean linear history
git log --oneline --graph origin/develop -5

# Confirm both PR #5469 commits have identical content
git diff 5d617ca38 1172ababb --stat
# Should show no differences

Step 2: Verify develop contains everything master has

# Check that develop's tree is a superset of master's tree
git diff origin/master origin/develop --stat
# This should only show NEW commits on develop, nothing missing

Step 3: Reset master to develop

Since develop is ahead of master and contains all the same changes (plus more), the safest fix is to point master at develop's HEAD:

# Switch to master
git checkout master

# Reset master to match develop (fast-forward to develop's HEAD)
git reset --hard origin/develop

# Force push to fix remote
git push --force-with-lease origin master

Step 4: Verify the fix

# Confirm linear history
git log --oneline --graph origin/master -5
# Should show a clean linear line with no merge commits

# Confirm master and develop point to the same commit
git log --oneline -1 origin/master
git log --oneline -1 origin/develop
# Should show the same SHA

Expected Result

* a46d414aa fix: earned_on timing bug in payment services + job tracking in global admin (#5471)
* 40649fcdb feat: Add extra columns to competitions tables (#5472)
* 1172ababb fix: rescue PaymentError and render error from Stripe (#5469)
* 89e7d6eff fix: deduplicate accounting permissions when both V1 and V2 are enabled (#5468)
* 59115b2ec fix: gatekeep competitions

No merge commit, clean linear history.

Prevention

Configure git to always rebase when pulling:

git config --global pull.rebase true

And protect master/develop with branch protection rules that:

  • Require linear history (no merge commits)
  • Only allow squash or rebase merges from PRs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment