LoginSignup
1
2

More than 3 years have passed since last update.

GitLabから特定のファイルのみを取得するための手順(sparse-checkout)

Last updated at Posted at 2021-03-16

sparse-checkoutとは?

spareとは、「わずかな」「希薄な」という意味がある。
(参考)
https://eow.alc.co.jp/search?q=sparse

checkoutとは、ワーキングディレクトリを特定の状態に変更するためのコマンドを指す。
(参考)
https://kitsune.blog/git-command#checkout%EF%BC%88%E3%83%81%E3%82%A7%E3%83%83%E3%82%AF%E3%82%A2%E3%82%A6%E3%83%88%EF%BC%89%E3%81%A8%E3%81%AF

つまり、わずかな変化(今回の場合だとリポジトリ内の一部のファイル取得)が起こった状態にcheckout(変更する)という意味になる。

作業手順

以下は、カレントディレクトリがローカルリポジトリであることを前提とする

1.SPARSE CHECKOUTを有効にするために以下のコマンドを実行。

git config core.sparsecheckout true

参考
https://git-scm.com/docs/git-read-tree#_sparse_checkout

2.設定の一覧表示を確認するために以下のコマンドを実行。




git config -l

参考
https://note.nkmk.me/git-config-setting/

3.〜するために、git/info以下にsparse-checkoutという名前のファイルを作成。

vi .git/info/sparse-checkout

参考
https://git-scm.com/docs/git-read-tree#_sparse_checkout

4.リポジトリから得たいファイルをsparse-checkoutに記述する

sparse-checkout
aaa #aaaを対象ファイルに指定
!/hoge/bbb #hoge/bbbは対象から除外

5.下記コマンドで、現在のローカルリポジトリに指定したリモートリポジトリを追加します。

git remote add origin リモートリポジトリの場所

参考
https://www.atmarkit.co.jp/ait/articles/2005/08/news017.html

6.リモートリポジトリの変更内容をローカルリポジトリに反映するために下記コマンドを実行

git pull リモートの名前 ブランチの名前

参考
https://www.atmarkit.co.jp/ait/articles/2003/06/news019.html

作業全体を通しての参考
https://qiita.com/shimamchan/items/88f6d0ad6231faea762a
https://leico.github.io/TechnicalNote/Git/sparse-checkout

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2