cmcmnooe
cmcmnooe

Reputation: 59

Is there a way to remove merged branches from my feature branch?

I have a feature branch I started about 2 months ago. Occasionally, I have been merging in master to my feature branch to make sure it would still work with the production site. Now that I'm finished, someone wants to see only the work I did on the feature branch. Is there a way to remove the merges of master I have made so that the diff would only contain my work on the feature branch?

Upvotes: 0

Views: 128

Answers (2)

Schwern
Schwern

Reputation: 165586

You have a few options. Since this is Github the simplest would be to put up your branch as a draft Pull Request. Then they can use the Github review tools to view your changes and commits.

Your reviewer can use use the normal Git tools to look at your changes. The revision selection master..<your branch> will select commits which are reachable from your branch excluding those reachable from master; that means it will only reference the commits on your branch. It will show the merge commits, but not what has been merged. So git diff master..<your branch> to see the diff and git log master..<your branch> to see just your commits. See gitrevisions for more.

If you truly want to eliminate the update merges you can rebase your commits on top of master. This will effectively rewrite your branch as if you wrote it on top of the current version of master all along. There might be conflicts. While this is a good option to clean up your history, I do it myself regularly, it's very easy to get confused. I don't recommend this option if you're still learning Git and don't have an expert handy to guide you through the potential issues.

Upvotes: 1

Romain Valeri
Romain Valeri

Reputation: 22067

Typically, if your feature branch was branched off develop for example, you would do

git diff develop..feature

and the see overall diff brought by feature commits which are not on develop.

Alternatively, you could use the same range of refspecs (develop..feature) to feed to git log and obtain the commits themselves. I guess it depends on your review process.


Edit after comments :

(redacted, my answer was suboptimal because the cherry-pick would have brought back the merge commits. Go for a rebase like Schwern suggests)

Upvotes: 0

Related Questions