Git: Generate patch of all commits made on "feature" branch without referring to commit IDs

4k views Asked by At

We maintain two versions of our application in two branches: free and master (master being the premium version of our application). These branches are fairly similar but the master branch has a few extra application features that the free version doesn't, so we need to maintain the two branches ongoing.

Regularly we need to fix bugs or add features to the free branch, which we need to have applied to the master branch when they're done. When I have such work to do, I'll start a new branch based on free called, for example, newfeature. When I'm done the feature, newfeature has X new commits.

Before I merge newfeature back into free I'd like to know what command I can use to generate a patch from all the commits contained in newfeature that now need to be applied to master. Currently, I'm just doing this:

git format-patch aa99f9..e94904

As far as I know how to do, I have to actually look up the specific commit IDs of when I branched newfeature, and the last commit in newfeature, which is a drag. I'm not interesting in commit IDs and I don't want to have to type them in.

I want there to be a single command that I can consistently use in which git will figure out which commits I'm talking about. It's the same pattern every time: given branch newfeature, I want to generate a patch of the commits from the common ancestor of newfeature and free to the latest commit on newfeature.

Is there some changeset expression out there that will obviate the need to manually look up commit IDs?

P.S.: AFAIK, I cannot use git rebase to do this task because that will merge the entire free branch onto master. I just want to merge the commits that are unique to the newfeature branch onto master.

1

There are 1 answers

0
Andrew Johnson On

Specifically what you're asking for is:

git format-patch `git merge-base newfeature free`..newfeature

You could probably save some time by doing this:

git checkout master
git cherry-pick `git merge-base newfeature free`..newfeature

Depending on your workflow, you might just have to create the patch before you merge in your feature. i.e.:

git checkout newfeature
git rebase free
git format-patch free

It does sound a but like your workflow could be improved by simply basing premium off of free and merging the free features into the premium branch.