The Hackerlab at `regexps.com`

## Basic Branching and Merging

up: arch next: Patch Logs and ChangeLogs prev: Basic Revision Control

When a single development path splits into two paths, that's called a branch . Typically, a branch is followed by a merge -- adding the changes made in a branch back to the branch from which it diverged.

This chapter explains how to create a branch and the simplest way to merge changes from two branches. Later chapters will explain fancier techniques, useful in more complex situations.

### Tagging

In `arch` , branches are "tags".

A tag is an alternative name for some revision. For example, one could use the tag `release-candidate` to name whatever revision people should download for testing purposes, regardless of what branch, version, or patch level the release candidate happens to be on.

In `arch` , tags are revisions on ordinary branches. For example, suppose we are developing `arch--devo--0.5` and want to create a tag `release-candidate` to mark revisions which "early adopters" should test. First, create a development path for the tag:

          % larch make-branch arch--release-candidate
          % larch make-version arch--release-candidate--0.5

To tag a specific revision, use the command:

          % larch tag SOURCE-REVISION TAG-REVISION

Note that `source-revision` and `tag-revision` may be abbreviated. For example, to tag the most recent revision of `arch--devo` :

          % larch tag arch--devo arch--release-candidate

or

          % larch tag arch--devo--0.5 arch--release-candidate--0.5

or

          % larch tag arch--devo--0.5--patch-37 \
                     arch--release-candidate--0.5

After such a command, you can retrieve the tagged revision in the ordinary way:

          % larch get arch--release-candidate--0.5

Note that when you `get` a tag that way, the default version of the resulting project tree is the tag's version, not the tagged version (see Labelling Project Trees).

You can always update a tag, making it point to a later revision, again using the `tag` command:

          % larch tag arch--devo--0.5--patch-53 \
                     arch--release-candidate--0.5

You can see the history of a tag in the usual way, too:

          % larch revisions --summary arch--release-candidate--0.5
          base-0
              tag of joe.hacker@gnu.org--arch/arch--devo--0.5--patch-37
          patch-1
              tag of joe.hacker@gnu.org--arch/arch--devo--0.5--patch-53

### Creating a Branch

There is another way to create a branch. This technique is slower, but has the side effect of leaving you with a working directory for the new branch. The effect on the repository is the same as when using the `tag` command.

Creating a new branch from an existing branch can be accomplished by this sequence of commands:

          % larch prepare-branch OLD-REVISION NEW-BRANCH-VERSION WORKING-DIR
          % cd WORKING-DIR
          [...edit log message...]
          % larch finish-branch

but it is worth deeply understanding that `prepare-branch` is equivalent to:

          # This command gets the source tree for the revision we
          # are branching from:
          #
          % larch get OLD-REVISION WORKING-DIR

          # These commands switch the working directory to the
          # new branch:
          #
          % cd WORKING-DIR
          % larch add-log NEW-BRANCH-VERSION
          % larch set-tree-version NEW-BRANCH-VERSION

          # These commands create a "continuation" base-revision
          # for the new branch:
          #
          % larch make-log

and that `finish-branch` is the same as:

          % larch make-branch NEW-BRANCH
          % larch make-version NEW-BRANCH-VERSION
          % larch commit --continuation OLD-REVISION

For example, to create a branch `hello--experimental--1.0` from the latest revision of `hello--devo--1.0` , use:

          % larch prepare-branch hello--devo--1.0 \
                                hello--experimental--1.0 \
                                wd

          % cd wd

          [...edit log message...]

          % larch finish-branch

### Distributed Branches

There is no requirement that a branch be stored in the same archive as the revision from which it branched. For example, you can create a private archive, and store some branches there -- only merging those changes back into the shared archive when they are ready.

Here's a tip: make your private archive your default archive. Use fully-qualified version and revision names when getting or committing revisions in the shared archive. This makes it less likely that you'll accidently make unintended changes to the shared archive.

### whats-missing Revisited

If you have a project tree for a branch, you might want to know what has happened in the version from which you branched.

The `whats-missing` is used for this. In a working directory for a branch, use:

          % larch whats-missing --summary ORIGINAL-VERSION

where `ORIGINAL-VERSION` is the version name of the version from which you branched. Actually, `ORIGINAL-VERSION` can be any version for which your project tree has a patch log.

The `whats-missing` command is explained in greater detail in the next chapter (see Patch Logs and ChangeLogs).

### update and replay Revisited

Similarly, `update` and `replay` work for any version for which a project tree has a patch log, such as a version from which a branch occurred:

          % larch update OLD-DIR NEW-DIR [archive/]VERSION

          % larch replay OLD-DIR NEW-DIR [archive/]VERSION

### Merging After a Branch

The simplest use of branching and merging is this: you have one development path, call it the "trunk". You form a branch from that development path, which we'll just call "the branch".

To make some changes, you do your work on the branch: check out the latest revision from the branch, make changes, commit, make more changes, commit again, etc.

As you work, you might sometimes need to "catch up" to changes made to the trunk. You can do that by using `update` or `replay` .

When you're done, and the branch is fully up-to-date with the trunk, you can check out the latest branch revision, then commit that version to the trunk. All of the changes that you made on the branch will be summarized into a single patch.

There are more complicated and more realistic uses of branches. These are the subjects of the next several chapters.

arch: The arch Revision Control System
The Hackerlab at `regexps.com`