mikosty
mikosty

Reputation: 11

How to force changed master history to feature branches based on old history?

My colleague changed history of our master and my feature-branch is based on old history of masters. Simple rebase didn't change my branchs' history to the new (changed) history.

Is cherry picking my only option or is there a simpler way to solve this? Creating a new branch would mess up our comment history on Gitlab about merge request. Also not sure what would happen with Gitlabs auto merge with differing histories.

Desired outcome would be similar history on master and feature-branch with feature-branch having my commits on top of it.

Upvotes: 1

Views: 159

Answers (1)

Romain Valeri
Romain Valeri

Reputation: 21998

Update your local version of master (it will be a forced update (marked with a + sign in fetch output) since histories differ)

git checkout master
git pull

Then you'll be able to cherry-pick or rebase your commits on top of newly updated master. Here with cherry-pick :

git checkout feature-branch
git log
# in git log output, spot the commit SHAs of the commits you need ans store them

git cherry-pick <commitSHA> <otherCommitSHA>

(Conflicts might arise. If so, resolve them as usual)

Now your feature-branch can be merged back into master (arguably through a PR) without history problems.

Upvotes: 1

Related Questions