Slightly less frustrating `git rebase` conflict resolution

@peeja.com

Let's say you've got a branch, style-guide, where you've been applying your new style guide rules to your content, but some of the content you were working with was still dummy content. Now there's a new branch, real-content, where that text has been updated with, well, real content, and you want to rebase your changes on top of them. Unsurprisingly, you've got a conflict:

<<<<<<< HEAD
Lorem ipsum is typically a corrupted version of De finibus bonorum et malorum, a
1st-century BC text by the Roman statesman and philosopher Cicero, with words
altered, added, and removed to make it nonsensical and improper Latin.  The
first two words are the truncation of dolorem ipsum ("pain itself").

Versions of the Lorem ipsum text have been used in typesetting since the 1960s,
when advertisements for Letraset transfer sheets popularized it.  Lorem ipsum
was introduced to the digital world in the mid-1980s, when Aldus employed it in
graphic and word-processing templates for its desktop publishing program
PageMaker.  Other popular word processors, including Pages and Microsoft Word,
have since adopted Lorem ipsum, as have many LaTeX packages, web content
managers such as Joomla! and WordPress, and CSS libraries such as Semantic UI.
=======
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
>>>>>>> caac0da (Address style guide)

The top part is the new content (actually stolen from Wikipediashh). On the branch you're rebasing onto, real-content, replaces the lorem ipsum text in the bottom part. But you're getting a conflict because you changed something about the lorem ipsum in your style-guide branch. Remember that rebasing your branch onto real-content means starting from real-content and replaying your changes—and since you changed text that's no longer there, git has no idea what you want to do. You need to somehow extract the intentions of the commit we're trying to replay and figure out the right way to apply them to the new text.

It sure would help if you could see what your changes actually were.

This has frustrated me for way too long. Now, there is a solution that the git ecosystem will try to point you towards, and that's using a merge tool. VS Code has one built in, called the "Merge Editor"—you'll see a button that says "Resolve in Merge Editor". That'll kind of show you what's up, but personally, I've always found it a little confusing. Maybe it's just me. But if it's also you, check this out:

git show REBASE_HEAD

When you're in the middle of a rebase, HEAD is the commit on top of which you're replaying the next changes (so, the branch you're rebasing onto followed by any commits you've already replayed during this rebase), the working tree and the staged changes contain git's attempt at replaying the changes, and the REBASE_HEAD is the original commit with the changes you're trying to replay. That's what you want to look at! Those are your changes!

If the commit is large and you want to narrow in on this one file (or several), you can use:

git show REBASE_HEAD -- the/file.txt [and/maybe.txt some/others/too.txt]

Let's see what we did:

$ git show REBASE_HEAD -- content
commit caac0da1583cfcfae0e72495334d209bfd8577aa (style-guide)
Author: Style Guru <styleguru@totally-not-wikipedia.example>
Date:   Mon Sep 8 12:52:20 2025 -0400

    Address style guide

diff --git a/content b/content
index 23ba63a..7b95d6b 100644
--- a/content
+++ b/content
@@ -1,6 +1,6 @@
 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
-incididunt ut labore et dolore magna aliqua.  Ut enim ad minim veniam, quis
+incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
 nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
 Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
-fugiat nulla pariatur.  Excepteur sint occaecat cupidatat non proident, sunt in
+fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
 culpa qui officia deserunt mollit anim id est laborum.

Aha! The old text had two spaces after the periods, and we updated it to one! So that was our intention, and we can apply that to the new content easily. Conflict resolved!

It's such a small thing. But this made my life a whole lot easier today, and I hope it does the same for you.

peeja.com
Petra Jaros

@peeja.com

Essential. Hot. In Progress.

Post reaction in Bluesky

*To be shown as a reaction, include article link in the post or add link card

Reactions from everyone (0)