Avba
Avba

Reputation: 15266

How to rebase already merged commits

I need to retroactively rebase merged commits from master onto a feature branch.

The feature branch was branched off of master (feature branch is the the blue line in the picture), then there were multiple commits on the feature branch (blue dots) , then master was merge committed back to the feature branch (instead of rebased - master is the red line in the picture).

So I need to "go back" 2 merge commits and rebase them instead while keeping the feature branch intact.

enter image description here

Upvotes: 0

Views: 1139

Answers (2)

Yiftizur
Yiftizur

Reputation: 96

You can also reset your branch to the commit before you split with the master branch, and then commit all your changes into 1 squashed commit. After that, simply rebase on master.

so, on your branch:

git reset --soft <commit SHA>
git add <All changes>
git commit -m "<commit message>"
git rebase master

Upvotes: 2

Istvan
Istvan

Reputation: 8552

You can use git rebase -i and replace "pick" on the second and subsequent commits with "squash" or "fixup".

Detailed description here:

https://git-scm.com/docs/git-rebase#_interactive_mode

After you did that you need to push to the remote repo (I think with a force).

Upvotes: 0

Related Questions