GitHubから特定のフォルダをダウンロードする
GitHub上のあるリポジトリの中の任意のサンプルプロジェクトだけ取得したい場合が多々あります。
これまでは1つのサンプルプロジェクトを取得するためにリポジトリ全体をclone
していました。
これは実際時間的にも容量的にもかなり無駄が多くなんとかならないかなと思いました。
調べてみると、GitHubのSubversionでexportする機能を使うことでディレクトリ単位でソースコードを取得できることがわかりました。
Windowsの場合、まずはSubversionのクライアントをインストールする必要があります。
環境
- Windows10 Pro 1903
Subversionクライアントのインストール
いくつかあるようですが、今回はなんとなく目についたSlikSVN
というクライアントを選びました。
こちらからダウンロードします。
zipを解凍して中のmsi
形式のインストーラを実行し、案内に従ってインストールを完了します。
インストール後の確認
インストールされたかコマンドラインから確認してみましょう。
コマンドプロンプトやPowerShellなどのコマンドラインを起動し、svn --version
を実行します。
C:\Users\hoge>svn --version svn, version 1.12.0-SlikSvn (SlikSvn/1.12.0) compiled May 28 2019, 13:44:56 on x86_64-microsoft-windows6.2.9200 Copyright (C) 2019 The Apache Software Foundation. This software consists of contributions made by many people; see the NOTICE file for more information. Subversion is open source software, see http://subversion.apache.org/
バージョン情報が表示されればOKです。
GitHubからディレクトリのダウンロード
これはXamarin
というリポジトリ内のXamarinComponents/Android/ARCore/samples/
ディレクトリです。
このサンプルプロジェクトだけ取得してみます。
masterブランチから取得する場合
svnを使ってダウンロードする場合、対象のURLを一部書き換える必要があります。
元: https://github.com/xamarin/XamarinComponents/tree/master/Android/ARCore/samples ↓ 後: https://github.com/xamarin/XamarinComponents/trunk/Android/ARCore/samples
tree/master
の部分をtrunk
に変更します。
このURLを使ってsvnコマンドでダウンロードします。
svn export https://github.com/xamarin/XamarinComponents/trunk/Android/ARCore/samples
コマンドを実行したディレクトリに対象のディレクトリ(この場合だとsamples
)がダウンロードされます。
C:\Users\hoge>svn export https://github.com/xamarin/XamarinComponents/trunk/Android/ARCore/samples A samples A samples\HelloAR.sln A samples\HelloAR A samples\HelloAR\Assets A samples\HelloAR\Assets\andy.obj ...
master以外のブランチから取得する場合
masterブランチではtree/master
をtrunk
と変えましたが、tree
をbranches
に変えます。
元: https://github.com/xamarin/XamarinComponents/tree/google-billing-android/Android/ARCore/samples ↓ 後: https://github.com/xamarin/XamarinComponents/branches/google-billing-android/Android/ARCore/samples
同様に以下のようにsvn export
コマンドでダウンロードします。
svn export https://github.com/xamarin/XamarinComponents/branches/google-billing-android/Android/ARCore/samples
C:\Users\shuhey>svn export https://github.com/xamarin/XamarinComponents/branches/google-billing-android/Android/ARCore/samples A samples A samples\HelloAR.sln A samples\HelloAR A samples\HelloAR\Assets A samples\HelloAR\Assets\andy.obj ...