Hone

Lessons · Git · the free way out of a merge or rebase

The free way out

While a merge or a rebase is stopped, git is holding the state you started from. --abort puts it back exactly.

Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.

What it is for

A conflict you do not understand is a conflict you should not resolve. Aborting costs nothing and a wrong resolution costs a change nobody will ever flag.

How to think about it

Abort, look at both branches with the pressure off, and start again knowing what you are choosing between.

Worked example

git merge feature
Stopped, with conflicts.
git status --short
UU f.txt.
git merge --abort
And back.
git status --short
Silence: the tree is exactly as it was.
cat f.txt
ours -- your branch's version, untouched.
git log --oneline
Two commits. No half-finished merge in the history.

Your turn

Get out of the stopped merge and back to where you started.

git merge 

The trap

Using reset --hard to escape a stopped merge. It usually works and it also throws away anything else uncommitted; --abort is the one that knows what it is undoing.

Practise the free way out of a merge or rebase on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.