Difference between revisions of "Developer Guide - Git Workflows"

From bering-uClibc
Jump to: navigation, search
(Rule: Merge upwards paragraph)
(Rule: Merge upwards)
Line 35: Line 35:
  
 
This gives a very controlled flow of fixes. If you notice that you have applied a fix to e.g. <span style="color:#8B4513">'''''master'''''</span> that is also required in <span style="color:#8B4513">'''''maint'''''</span>, you will need to cherry-pick it (using [http://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html git-cherry-pick(1)]) downwards. This will happen a few times and is nothing to worry about unless you do it very frequently.
 
This gives a very controlled flow of fixes. If you notice that you have applied a fix to e.g. <span style="color:#8B4513">'''''master'''''</span> that is also required in <span style="color:#8B4513">'''''maint'''''</span>, you will need to cherry-pick it (using [http://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html git-cherry-pick(1)]) downwards. This will happen a few times and is nothing to worry about unless you do it very frequently.
 +
 +
=== Topic branches ===
 +
Any nontrivial feature will require several patches to implement, and may get extra bugfixes or improvements during its lifetime.
 +
 +
<span style="color:#D00000">Committing everything directly on the integration branches leads to many problems</span>: Bad commits cannot be undone, so they must be reverted one by one, which creates confusing histories and further error potential when you forget to revert part of a group of changes. Working in parallel mixes up the changes, creating further confusion.
 +
 +
Use of "topic branches" solves these problems. The name is pretty self explanatory, with a caveat that comes from the "merge upwards" rule above:
 +
 +
==== <span style="color:green">Rule: '''Topic branches'''</span> ====
 +
* Make a side branch for every topic (feature, bugfix, …). Fork it off at the '''oldest integration branch''' that you will eventually want to merge it into. For example for a bugfix in <span style="color:#8B4513">'''''maint'''''</span> fork your topic branch from <span style="color:#8B4513">'''''maint'''''</span>. For a new feature fork it off from the <span style="color:#8B4513">'''''master'''''</span> (<span style="color:#D00000">never from the <span style="color:#8B4513">'''''next'''''</span> that is an experimental branch that can be rewind</span>).
 +
 +
Many things can then be done very naturally:
 +
 +
* To get the feature/bugfix into an integration branch, simply merge it. If the topic has evolved further in the meantime, merge again. (Note that you do not necessarily have to merge it to the oldest integration branch first. For example, you can first merge a bugfix to <span style="color:#8B4513">'''''next'''''</span>, give it some testing time, and merge to <span style="color:#8B4513">'''''maint'''''</span> when you know it is stable.)
 +
* If you find you need new features from the branch <span style="color:#8B4513">'''''other'''''</span> to continue working on your topic, merge <span style="color:#8B4513">'''''other'''''</span> to <span style="color:#8B4513">'''''topic'''''</span>. (However, do not do this "just habitually", see below.)
 +
* If you find you forked off the wrong branch and want to move it "back in time", use [http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html git-rebase(1)].
 +
 +
Note that the last point clashes with the other two: <span style="color:#D00000">a topic that has been merged elsewhere should not be rebased</span>. See the section on RECOVERING FROM UPSTREAM REBASE in [http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html git-rebase(1)].
  
 
[[Category:Developer Guide]]
 
[[Category:Developer Guide]]

Revision as of 11:55, 17 August 2012

Description

This document attempts to write down and motivate some of the workflow elements used for managing the development of Bering-uClibc with git. This guide was an adapted version of the GitWorkflows document that is used for the git project.

Separate changes

As a general rule, you should try to split your changes into small logical steps, and commit each of them. They should be consistent, working independently of any later commits, pass the build, etc. This makes the review process much easier, and the history much more useful for later inspection and analysis, for example with git-blame(1) and git-bisect(1).

To achieve this, try to split your work into small steps from the very beginning. It is always easier to squash a few commits together than to split one big commit into several. Don’t be afraid of making too small or imperfect steps along the way. You can always go back later and edit the commits with git rebase --interactive before you publish them. You can use git stash save --keep-index to try a build independent of other uncommitted changes; see the EXAMPLES section of git-stash(1).

Managing Branches

There are two main tools that can be used to include changes from one branch on another: git-merge(1) and git-cherry-pick(1).

Merges have many advantages, so we try to solve as many problems as possible with merges alone. Cherry-picking is still occasionally useful; see "Merging upwards" below for an example.

Most importantly, merging works at the branch level, while cherry-picking works at the commit level. This means that a merge can carry over the changes from 1, 10, or 1000 commits with equal ease, which in turn means the workflow scales much better to a large number of contributors (and contributions). Merges are also easier to understand because a merge commit is a promise that all changes from all its parents are now included.

There is a tradeoff of course: merges require a more careful branch management. The following subsections discuss the important points.

Graduation

As a given feature goes from experimental to stable, it also "graduates" between the corresponding branches of the software. Bering-uClibc uses the following integration branches:

  • maint tracks the commits that should go into the next "maintenance release", i.e., update of the last released stable version;
  • master tracks the commits that should go into the next release;
  • next is intended as a testing branch for topics being tested for stability for master.

Each of the three branches is usually a direct descendant of the one above it.

Conceptually, the feature enters at an unstable branch (usually next), and "graduates" to master for the next release once it is considered stable enough.

Merging upwards

The "downwards graduation" (for example from next to master) discussed above cannot be done by actually merging downwards, however, since that would merge all changes on the unstable branch into the stable one. Hence the following:

Rule: Merge upwards

Always commit your fixes to the oldest supported branch that require them. Then (periodically) merge the integration branches upwards into each other.

This gives a very controlled flow of fixes. If you notice that you have applied a fix to e.g. master that is also required in maint, you will need to cherry-pick it (using git-cherry-pick(1)) downwards. This will happen a few times and is nothing to worry about unless you do it very frequently.

Topic branches

Any nontrivial feature will require several patches to implement, and may get extra bugfixes or improvements during its lifetime.

Committing everything directly on the integration branches leads to many problems: Bad commits cannot be undone, so they must be reverted one by one, which creates confusing histories and further error potential when you forget to revert part of a group of changes. Working in parallel mixes up the changes, creating further confusion.

Use of "topic branches" solves these problems. The name is pretty self explanatory, with a caveat that comes from the "merge upwards" rule above:

Rule: Topic branches

  • Make a side branch for every topic (feature, bugfix, …). Fork it off at the oldest integration branch that you will eventually want to merge it into. For example for a bugfix in maint fork your topic branch from maint. For a new feature fork it off from the master (never from the next that is an experimental branch that can be rewind).

Many things can then be done very naturally:

  • To get the feature/bugfix into an integration branch, simply merge it. If the topic has evolved further in the meantime, merge again. (Note that you do not necessarily have to merge it to the oldest integration branch first. For example, you can first merge a bugfix to next, give it some testing time, and merge to maint when you know it is stable.)
  • If you find you need new features from the branch other to continue working on your topic, merge other to topic. (However, do not do this "just habitually", see below.)
  • If you find you forked off the wrong branch and want to move it "back in time", use git-rebase(1).

Note that the last point clashes with the other two: a topic that has been merged elsewhere should not be rebased. See the section on RECOVERING FROM UPSTREAM REBASE in git-rebase(1).