0

How to easily rebase and squash a lot of commits without dealing with conflicts?

By rebase and squash I mean transforming a lot of commits into a single one on top of a target branch.

rerere sometimes isn't enough to avoid the endless repetitions of conflicts prompts.

HectorJ
  • 5,814
  • 3
  • 34
  • 52

1 Answers1

0

Let's say you want to rebase on master while squashing all your commits, and you have a clean working tree.

git fetch && \
git merge origin/master && \
git reset origin/master && \
git add --all && \
git commit -m "your new commit message"
  1. you fetch the latest updates from your remote
  2. you merge your rebase-target branch into your current branch, so the only diff between the two of them comes from your added commits
  3. you reset your branch to your target branch, erasing your commits while keeping your changes in the newly dirty working tree
  4. you add all those changes
  5. you create a new commit

This way you end up with a single fresh new commit on top of origin/master, and at most you dealt with conflicts only once.

HectorJ
  • 5,814
  • 3
  • 34
  • 52
  • 1
    Is this actually an answer to the question? It's not clear to me how this answers it. – joanis Jan 12 '23 at 13:58
  • 2
    You are not _soft_ resetting, but resetting with _mixed_ mode. And there's a duplicate for this question. Let me find it – knittl Jan 12 '23 at 15:26