Mack M.
Mack M.

Reputation: 103

Remove all commits that were merged from a specific branch

I have been building a feature on a branch (lets call it 'feature1') that I've merged into my master branch ('master') several times. Ive merged other feature branches into master intermittently, so my merge commits that come from 'feature1' into 'master' are a bit sprinkled throughout other commits over the last week.

What I want to do: Remove all merges from 'feature1' -> 'master' as if they never happened. All other work that came from other branches, I want to leave in 'master' untouched.

Is there a way to remove commits that only came from a particular source? i.e. just the 'feature1' branch?

Upvotes: 3

Views: 135

Answers (1)

gcbenison
gcbenison

Reputation: 11963

Well, if this is something you just need to do once, and the number of merges is manageable, then you could do it like this:

git rebase -i <sha1 of master before I started merging evil branch in>

and manually edit out the merge commits you don't want.

I'm sure there is a more automated way of doing this with filter-branch and such, but if it's a one-time thing, you might get the job done faster just using rebase.

Upvotes: 3

Related Questions