红穆笔记

git archive

從代碼樹創建文件歸檔

100% 瀏覽器本地處理 0 數據上傳

常用示例

從當前 HEAD 內容創建 `.tar` 歸檔並輸出到標準輸出

git archive {{[-v|--verbose]}} HEAD

使用 Zip 格式並顯示詳細進度

git archive {{[-v|--verbose]}} --format zip HEAD

將 Zip 歸檔輸出到指定文件

git archive {{[-v|--verbose]}} {{[-o|--output]}} {{路徑/到/文件.zip}} HEAD

從指定分支的最新提交內容創建 `.tar` 歸檔

git archive {{[-o|--output]}} {{路徑/到/文件.tar}} {{指定分支}}

使用特定目錄的內容創建歸檔

git archive {{[-o|--output]}} {{路徑/到/文件.tar}} HEAD:{{路徑/到/目錄}}

爲歸檔中的每個文件添加前綴路徑

git archive {{[-o|--output]}} {{路徑/到/文件.tar}} --prefix {{路徑/到/前綴路徑}}/ HEAD

提示:花括號{{…}}是需要替換的參數(路徑、文件名等);命令只在本機終端執行,本站不保存任何輸入。

英文原文對照

展開英文說明與示例(來源 tldr-pages)

Create an archive of files from a tree. More information

Create a `.tar` archive from the contents of the current `HEAD` and print it to `stdout`

git archive {{[-v|--verbose]}} HEAD

Use the Zip format and report progress verbosely

git archive {{[-v|--verbose]}} --format zip HEAD

Output the Zip archive to a specific file

git archive {{[-v|--verbose]}} {{[-o|--output]}} {{path/to/file.zip}} HEAD

Create a `.tar` archive from the contents of the latest commit of a specific branch

git archive {{[-o|--output]}} {{path/to/file.tar}} {{branch_name}}

Use the contents of a specific directory

git archive {{[-o|--output]}} {{path/to/file.tar}} HEAD:{{path/to/directory}}

Prepend a path to each file to archive it inside a specific directory

git archive {{[-o|--output]}} {{path/to/file.tar}} --prefix {{path/to/prepend}}/ HEAD

命令信息

命令名git archive
用途從代碼樹創建文件歸檔
適用平臺通用
示例數量6 條
官方文檔https://git-scm.com/docs/git-archive
數據來源tldr-pages(CC-BY-4.0)· 社區中文翻譯

常見問題

git archive 命令是做什麼的?

從代碼樹創建文件歸檔

git archive 怎麼用?

頁面按場景列出了6 條常用示例:每條示例先說明用途,再給出可直接複製的完整命令(花括號裏是需要替換的參數)。

git archive 最常用的操作是什麼?

從當前 HEAD 內容創建 `.tar` 歸檔並輸出到標準輸出:git archive {{[-v|--verbose]}} HEAD

命令裏的花括號是什麼意思?

花括號{{…}}表示需要替換成你自己的值,例如路徑、文件名;同名參數方括號(如 [-C|--directory])表示可選寫法。