Git branch with ff merges from master - remove ff merges

61 views Asked by At

I have this situation in our codebase.

We created a branch but, mistakingly, we merged master into that a few times (which resulted in a few fast forward merges). Now we have a mix of commits done in the branch and code merged at some point during the branch life (which is just a week long though).

How can I remove the fast forward and just keep the commits we made in the branch?

I was thinking of doing this.

Create a brand new branch from the commit I created the other branch, then list all of the commits made in the previous branch:

git rev-list BRANCH_NAME ^master

And then cherry picking the commits listed by that command into the new branch

git cherry-pick be530cec7748e037c665bd5a585e6d9ce12bc8bc

Would this be the right way to do so? I am worried that I might get the fast-forward too (which obviously did not create a commit though).

I am fairly new to Git so I would appreciate any suggestions!

Thanks! Roberto

1

There are 1 answers

0
bcmcfc On BEST ANSWER

I'd suggest an interactive rebase.

$ git rebase -i lastKnownGoodCommitHash

You'll need to manually select the commits you want to keep.

To remove one you can simply cut out the line containing its hash (this will become apparent when you start the process).

There's an article on github explaining it in more depth: https://help.github.com/articles/interactive-rebase