Rebase Conflicts

Resolving Conflicts During a Rebase

Meanwhile main gets a fix: pages are stable only if equal prices or ratings always sort the same way, so the query breaks ties by id, on the SQL line the limit commit also changed. Turn on rerere (rerere), then rebase:

A rebase that stops on a conflictShell
git config set rerere.enabled true
git switch -q main
# Edit app.js: add ", id" to ORDER BY so equal values sort by id
git commit -qam "Break sort ties by id so pages are stable"
git switch -q paginate-api
git rebase main
sed -n '/^<<<<<<</,/^>>>>>>>/p' app.js
Output
Auto-merging app.js
CONFLICT (content): Merge conflict in app.js
...
Recorded preimage for 'app.js'
...
<<<<<<< HEAD
         FROM books ${where} ORDER BY ${order}, id`,
||||||| parent of 237ad84 (Add ?limit= to /api/books)
         FROM books ${where} ORDER BY ${order}`,
=======
         FROM books ${where} ORDER BY ${order} ${page}`,
>>>>>>> 237ad84 (Add ?limit= to /api/books)

The sides are swapped compared with a merge: during a rebase HEAD is the new base (main plus the commits already replayed), and your commit is "theirs", so git checkout --ours takes main's version. Keep both changes and continue; GIT_EDITOR=true accepts the message --continue would open in the editor:

Resolving the conflict and continuingShell
# Edit app.js: keep ", id" and ${page}, and delete the marker lines
git add app.js
GIT_EDITOR=true git rebase --continue
Output
Recorded resolution for 'app.js'.
[detached HEAD 6568474] Add ?limit= to /api/books
...
Successfully rebased and updated refs/heads/paginate-api.

A rebase can stop once per replayed commit, so a long branch may conflict again and again on the same lines, one more reason to rebase often and keep branches short.