jonathanbell
jonathanbell

Reputation: 2637

How to squash commits that contain merge commits without re-resolving conflicts?

I've been working on a long running branch and I've been pulling another branch (develop) into my branch every so often. I've also been making small WIP (Work in Progress) commits as I go along. I'd like to rebase/squash all the WIP commits including the merge commits from develop branch and fast forward/update my branch to the present. However, some of the pulls from develop did have merge conflicts and this seems to be causing me a problem.

I tried git rebase -i <hash> and git rebase --rebase-merges -i <hash> but both times, Git asks me to re-resolve all the merge commits/conflicts (all the way back to a month ago, in this case) and doesn't seem to be smart enough to just "update" my branch with the present state of develop branch and squash all of my WIP commits. I don't want to re-resolve all the conflicts.

Is there a clean/easy way of doing this?

Upvotes: 3

Views: 321

Answers (1)

VonC
VonC

Reputation: 1329072

An interactive rebase would require conflict resolution indeed.
You might try and train rerere on past commit merge resolution using contrib/rerere-train.sh.

Or you could create another branch where you cherry-pick your commits excluding the merge commits, and then squash them with a rebase -i. But this is manual and prone to error.

To detail the simpler alternative from torek's comment:

git reset --soft $(git merge-base your-feature-branch develop)
git commit -m "Your squashed commit message"
git pull --ff-only origin develop

Upvotes: 0

Related Questions