Post

Checkout Only the SVN Directories You Need with --depth

Checkout Only the SVN Directories You Need with --depth

Checkout Only the SVN Directories You Need with --depth

SVN でリポジトリ全体を checkout せず、必要な階層やディレクトリだけを取得したい場合は、--depth を使う。

ルートだけ checkout する

まずは作業コピーのルートだけを作る。

1
svn checkout --depth empty https://svn.example.com/repos/MyRepo/trunk MyRepo

第一階層のファイルとディレクトリ名まで見たい場合は、immediates にする。

1
svn checkout --depth immediates https://svn.example.com/repos/MyRepo/trunk MyRepo

--depth empty

このディレクトリ自体だけを取得し、配下のファイルやサブディレクトリは取得しない。

--depth immediates

直下のファイルとサブディレクトリまでは取得するが、サブディレクトリの中身は取得しない。

必要なディレクトリだけ取得する

作業コピーに入る。

1
cd MyRepo

必要なディレクトリを指定して、通常どおり中身まで取得する。

1
2
svn update --set-depth infinity ProjectA
svn update --set-depth infinity SharedLib

--depth empty で checkout した場合、対象ディレクトリを明示して --set-depth infinity を指定する。

取得済みのディレクトリを外す

あとから不要になったディレクトリは、exclude にする。

1
svn update --set-depth exclude SharedLib

これで SharedLib は作業コピーから除外される。

よく使う流れ

1
2
3
4
5
svn checkout --depth empty https://svn.example.com/repos/MyRepo/trunk MyRepo
cd MyRepo
svn update --set-depth infinity ProjectA
svn update --set-depth infinity SharedLib
svn update --set-depth exclude SharedLib

メモ

  • empty: このディレクトリ自体だけ。
  • immediates: 直下のファイルとサブディレクトリまで。ただし、その中身は取得しない。
  • infinity: 指定したディレクトリ以下をすべて取得する。
  • exclude: 指定したディレクトリを作業コピーから除外する。
This post is licensed under CC BY 4.0 by the author.