Skip to content
Justice Tech School

Aborting a Merge

If a merge goes wrong, git merge --abort returns to the state before it started. Same idea exists for rebase.

Example
echo one > a.txt && git add a.txt && git commit -qm 'first'
git switch -q -c x && echo x > a.txt && git commit -qam 'x'
git switch -q main && echo y > a.txt && git commit -qam 'y'
git merge x >/dev/null 2>&1; git status --short
git merge --abort
git status --short; cat a.txt

Result

UU a.txt
y

Exercise

Cancel a merge.

git merge 

Quiz Test

What does --abort do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.