git archive

git

書き方

git archive --format=tar.gz -o <file> <tree-ish>

あるコミット時点のファイルをtarやzipとして書き出します。.gitや追跡外のファイルが入らないので、フォルダーをそのまま圧縮するより綺麗な配布物になります。

よく使うオプション

オプション意味
--format=<fmt>tar, zip or tar.gz
-o <file>write to a file; the format is guessed from the name
--prefix=<dir>/put everything under one folder inside the archive
--add-file=<file>include an untracked file as well
--remote=<repo>let the server build it
-llist the formats this build supports

git archive --format=tar.gz -o app-1.2.0.tar.gz v1.2.0

a release tarball of exactly that tag

git archive --prefix=app/ -o app.zip HEAD

a zip whose contents sit inside app/

git archive -o src.zip HEAD -- src

only the src directory

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git archive は何をしますか。

あるコミット時点のファイルをtarやzipとして書き出します。.gitや追跡外のファイルが入らないので、フォルダーをそのまま圧縮するより綺麗な配布物になります。

Q. どう打ちますか。

git archive --format=tar.gz -o <file> <tree-ish> — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-archive