LoginSignup
32
32

More than 5 years have passed since last update.

gitで特定のタグのshallow repositoryを作る

Last updated at Posted at 2014-02-26

最新のコミットだけcloneしてくるときにgit clone --depth=1としてshallow repositoryを作ったりしますが、最新ではなく特定のタグを取ってきたいときに。

追記2/27

コメントでこんな方法もあるという情報が。

$ git clone --depth=1 -b v1.2 git://github.com/foo/bar

--branch
-b
Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s HEAD, point to branch instead. In a non-bare repository, this is the branch that will be checked out. --branch can also take tags and detaches the HEAD at that commit in the resulting repository.
https://www.kernel.org/pub/software/scm/git/docs/git-clone.html

簡単じゃないかー。ngyukiさんありがとうございます。

バリエーションまとめ

  • git clone 全部fetchしてmasterをチェックアウト
  • git clone -b refspec 全部fetchして特定ブランチ・タグをチェックアウト
  • git clone [-b refspec] --single-branch 指定したブランチ・タグのみfetchして(略)
  • git clone [-b refspec] --depth=n 指定したブランチ・タグの最新nコミットのみ(略)

以下元の記事

$ git init
$ git fetch --depth=1 git://github.com/foo/bar v1.2
$ git checkout FETCH_HEAD

参考にしたエントリではpullを使っていますが、この場合以下のようなエラーが出てしまいます。

error: Trying to write non-commit object 99700ffadab431edc6cf0c9d6a78d4a9ea5c18d6 to branch refs/heads/master
fatal: Cannot update the ref 'HEAD'.

pullなのでmasterをマージしようとするものの、一つもコミットしてないのでエラーになるのかなと。

なおpull/fetchに指定できるのはrefspecなので、コミットハッシュを指定することはできません。この場合はあきらめて全体をcloneするしかないようです。

参考

http://d.hatena.ne.jp/PvP/20080823/1219475545
http://stackoverflow.com/questions/8932389/git-shallow-clone-to-specific-tag

32
32
2

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
32
32