2

I am currently working on a project using git. Basically, my git tree consists of three branches :

  • Branch A : The origin branch, from which derives my work.
  • Branch B : A branch based on A. B contains development work (a new feature for A).
  • Branch C : For time management reasons, I also begun the development of incomplete experimental options for the new feature. This experimental code was added directly in B. So C is the clean up branch for B, only keeping the fully operational code.

The branch relationship can be represented in this fashion :

A head-> B -> commit 0 -> ... -> commit n -> C -> clean up commit

The branch B contains all the new feature's code, sometimes mixed with optional segments still in development. All the commits in C are deletion of the experimental parts.

The code in branch C is clean and I want to forge a patch from it. The patch should include all the changes from the last commit of C to A's head.

If I do git format-patch master --stdout > my_patch.patch, this produces a patch that will effectively end in the operational code. But this is not fine since, in the patch, the experimental code is added (through some commits in B) and then removed (clean up commits in C). In addition to not being smart at all, this also includes useless extra space (which means extra mail to share the patch with the community) and extra overhead at application.

How should I operate on these branches to produce a clean patch ? Note that I want to preserve the experimental work made so far in branch B, I just want not to include it in the patch.

Rerito
  • 5,886
  • 21
  • 47
  • 1
    Is there a specific reason you're not using [cherry-pick](https://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html)? – Mohamed Tarek Apr 09 '13 at 08:49
  • @MohamedTarek You recommend me to create a new branch deriving from __A__ and then cherry-pick the changes applied in __B__ ? Am I getting it correct ? – Rerito Apr 09 '13 at 08:56
  • This answer might be relevant, http://stackoverflow.com/a/1624723/ – Hasturkun Apr 09 '13 at 09:32
  • @Rerito Actually I meant, instead of producing a patch from **C** to apply on **A**, you would just cherry-pick the commits you want from **C** to **A**, and leave branch **B** intact. – Mohamed Tarek Apr 09 '13 at 09:43

1 Answers1

1
git checkout C              # alternately, do "git checkout -b C_NEW" for safety
git rebase --interactive A  # Your A branch

It will bring up an editor. Change all the "pick" text to "s" except the first one. This will "squish" all your commits into one commit.

You could have also have used cherry-pick (to pull out a few commits onto A), or git rebase --interactive (and deleted all the B commits to get C).

BraveNewCurrency
  • 12,654
  • 2
  • 42
  • 50
  • As a matter of fact, I used the combination of `git rebase -i` along with `git reset HEAD~` in each "grey" commit to split them and then the "squash" trick. I was looking for an answer that would spare me to put the hand in the crap but hey ... If I screw up things, I would not expect they'ld fix themselves on their own. Anyway, as your answer depicts quite well the procedure I followed, I accepted it ! – Rerito Apr 15 '13 at 11:15