ブランチの横断

The svn switch command transforms an existing working copy to reflect a different branch. While this command isn't strictly necessary for working with branches, it provides a nice shortcut. In our earlier example, after creating your private branch, you checked out a fresh working copy of the new repository directory. Instead, you can simply ask Subversion to change your working copy of /calc/trunk to mirror the new branch location:

$ cd calc

$ svn info | grep URL
URL: http://svn.example.com/repos/calc/trunk

$ svn switch http://svn.example.com/repos/calc/branches/my-calc-branch
U   integer.c
U   button.c
U   Makefile
Updated to revision 341.

$ svn info | grep URL
URL: http://svn.example.com/repos/calc/branches/my-calc-branch

ブランチに「切り替え」たあとでは、作業コピーの内容は、そのディレクトリを新しくチェックアウトした場合とまったく同じになります。そして、通常このコマンドを使うほうがより効率的です。たいていブランチはほんの少し内容が違うだけだからです。サーバはそのブランチディレクトリを反映させるための、作業コピーにしなくてはならない最小限の変更だけを、送信すれば済みます。

The svn switch command also takes a --revision (-r) option, so you need not always move your working copy to the HEAD of the branch.

もちろん、ほとんどのプロジェクトはcalcよりは もっと複雑で、複数のサブディレクトリを含んでいます。Subversionユーザは ブランチを利用するときにはよく、特定のやり方をします。:

  1. プロジェクトの「幹(trunk)」全体を新しいブランチディレクトリ にコピーする。

  2. 幹(trunk)の作業コピーの一部のみを ブランチにミラーする。

言い換えると、ユーザが特定のサブディレクトリ上でだけブランチの作業が起きる ことを知っている場合にはsvn switchを使ってブランチに そのサブディレクトリのみを移動します。(あるいは、たった一つの作業ファイル だけをブランチに switch することさえあります!) その方法では、作業コピー のほとんどすべての更新を普通の「幹(trunk)」から従来どおり受け取ることが できますが、切り替えた部分だけは変更されることなく残ります(もしブランチ に対して誰かが変更点をコミットしさえしなければ)。この機能は 「混合作業コピー」という概念にまったく新しい次元を付け加える ことになります—作業コピーは作業リビジョンの混合を含むことができる だけではなく、リポジトリ位置の混合も含むことができます。

もし作業コピーが異なるリポジトリ位置からのスイッチされたサブツリー をいくつか含むなら、それは普通に機能し続けます。更新すると、 それぞれのサブツリーのパッチを適切に受け取るでしょう。コミットすると ローカル修正は一つの不可分の変更をリポジトリに適用するでしょう。

Note that while it's okay for your working copy to reflect a mixture of repository locations, these locations must all be within the same repository. Subversion repositories aren't yet able to communicate with one another; that's a feature planned for the future. [24]

svn switch は本質的にはsvn update の変種なので、同じ動作を共有します。作業コピー中のどのようなローカルの 変更もリポジトリから新しいデータが届くときに保存されます。これで あらゆる利口な小技がきくようになります。

たとえば/calc/trunk の作業コピーがありそれにいくつか 変更を加えたとします。それから突然、本当はブランチにやる変更だったことに 気づきます。問題ありません。作業コピーをsvn switch でブランチにスイッチしても、ローカルの変更はそのまま残ります。で、 それをブランチに対してテストし、コミットすることができます。



[24] You can, however, use svn switch with the --relocate option if the URL of your server changes and you don't want to abandon an existing working copy. See svn switch for more information and an example.