bmargulies
bmargulies

Reputation: 100050

git rebase equivalent of merge --squash

I've got a rather messy branch on my hands. It has undergone several instances of

git merge master

If I do the git rebase -i with a lot of squashed, I'll have to re-fix the conflicts that I resolved in the merges.

My impression is that

git checkout master
git merge --squash

would end up with the desired result without the manual remerging. Is my best bet:

git checkout master
git checkout -b clean-new-branch
git merge --squash my-messy-branch

and the reset my branch onto the end of clean-new-branch, abandoning my prior history?

Upvotes: 0

Views: 115

Answers (1)

poke
poke

Reputation: 387687

Assuming you have the following history:

     master               my-messy-branch
        ↓                        ↓
-- C -- C -- M -- M -- M -- M -- M

Where C are “clean” (or good) commits, and M are “messy” ones, and you want the following result:

     master   my-messy-branch
        ↓       ↙
-- C -- C --- C

Then it’s really simple to do so, without having to do an interactive rebase with squashing all those commits manually. Instead, you can just do a soft-reset on your messy branch:

git checkout my-messy-branch
git reset --soft master
git commit

This will create a single commit for all the changes in those M commits.

Upvotes: 1

Related Questions