Skip to content

Merge commit actions (revert with mainline, compare against parent)

A merge commit is the one commit with two "before" states, and that changes both of the things you would normally do with a commit. Undoing it is ambiguous — Git will not invert a merge until you say which of its parents you consider the mainline — and reading it is lopsided, because a merge's diff is always shown against its first parent and nothing else.

So a merge commit gets two entries of its own on its right-click menu. Revert merge opens the ordinary revert dialog, which grows a mainline picker as soon as it sees more than one parent (it is also in the ⌘K palette, and opens the same dialog). Compare against parent 1 / 2 reads the merge against whichever side you name, so you can see what the merged-in branch contributed and, separately, what the mainline had been doing in the meantime.

Reverting a merge commit with mainline 1 undoes the merged-in branch

Reverting a merge is the one revert Git refuses to guess at: a merge has two "before" states, so the dialog asks which parent is your mainline. Pick parent 1 to undo everything the merged-in branch brought, as one new commit — the usual way to back out a bad merge without rewriting history.

Reverting a merge commit with mainline 1 undoes the merged-in branch

Captured from the running app by this scenario.

Do this

  1. Select the v0.2.0 commit in the graph
  2. Open the command palette
  3. Pick Revert this commit from the palette
  4. Choose mainline parent 1 for the revert
  5. Confirm the revert

You should see

  • The revert dialog is shown
  • The revert mainline picker is shown
  • The repository HEAD commit subject contains Revert
  • The file rollback.ts does not exist in the working tree
  • The file rollback.test.ts does not exist in the working tree
  • The file README.md in the working tree contains Badges!

Comparing a merge commit against parent 1 shows the merged-in branch's files

A merge commit's regular diff panel always reads it against the mainline. To see the other side — or to make the first-parent reading explicit — compare the merge against either parent: against parent 1 you get exactly what the merged-in branch contributed, against parent 2 what the mainline had done in the meantime.

Comparing a merge commit against parent 1 shows the merged-in branch's files

Captured from the running app by this scenario.

Do this

  1. Select the v0.2.0 commit in the graph
  2. Compare the selected commit against parent 1

You should see

  • The compare-parent dialog is shown
  • The compare-parent diff lists the file rollback.ts
  • The compare-parent diff lists the file rollback.test.ts

This page is generated from apps/e2e/features/merge-commit-actions.feature, the end-to-end test that drives the feature it describes.

MIT licensed · Screenshots exported from the real app by the end-to-end suite.