Video in progress
A conflict came up in the middle of a rebase. What do you do now, and how do you safely go back?
I resolve the conflict, git add, and continue with git rebase --continue. I --skip a commit that is no longer needed, and if everything gets tangled, git rebase --abort returns the branch to its state before the rebase.
📖 Answer
A rebase reapplies commits one by one, so a conflict can come up separately in each commit. It is not one big conflict as in a merge.
git status # which files are in conflict
# fix the files
git add src/main/java/.../OrderService.java
git rebase --continue
This is where people often slip: during a rebase, ours and theirs have reversed meanings. --ours is the base you are putting your commits on top of (for example main), and --theirs is your commit.
Useful commands:
git rebase --skip: if this commit is no longer needed (for example, the same change has already gone intomain);git rebase --abort: cancel everything;- if you get lost even after an abort,
ORIG_HEADorgit reflogshows the old state.
If the same conflict keeps repeating on every commit, squash your commits before the rebase or turn on git rerere. On an old branch with a great many commits, a plain git merge origin/main is sometimes cheaper.
Sign up to mark studied questions and save your progress.