# git-archive
> 原文: [https://git-scm.com/docs/git-archive](https://git-scm.com/docs/git-archive)
## 名稱
git-archive - 從命名樹創建文件存檔
## 概要
```
git archive [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]
[-o <file> | --output=<file>] [--worktree-attributes]
[--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
[<path>…?]
```
## 描述
創建包含指定樹的樹結構的指定格式的存檔,并將其寫入標準輸出。如果<前綴>指定它被添加到存檔中的文件名前面。
_git archive_ 在給定樹ID時與給定提交ID或標記ID時的行為不同。在第一種情況下,當前時間用作存檔中每個文件的修改時間。在后一種情況下,使用引用的提交對象中記錄的提交時間。另外,如果使用tar格式,則提交ID存儲在全局擴展pax頭中;它可以使用 _git get-tar-commit-id_ 提取。在ZIP文件中,它存儲為文件注釋。
## OPTIONS
```
--format=<fmt>
```
生成的存檔的格式: _tar_ 或 _zip_ 。如果未給出此選項,并且指定了輸出文件,則盡可能從文件名推斷格式(例如,寫入“foo.zip”使輸出為zip格式)。否則輸出格式為`tar`。
```
-l
```
```
--list
```
顯示所有可用格式。
```
-v
```
```
--verbose
```
向stderr報告進度。
```
--prefix=<prefix>/
```
將<前綴> /前置到存檔中的每個文件名。
```
-o <file>
```
```
--output=<file>
```
將存檔寫入< file>而不是stdout。
```
--worktree-attributes
```
在工作樹中查找.gitattributes文件中的屬性(參見 [ATTRIBUTES](#ATTRIBUTES) )。
```
<extra>
```
這可以是歸檔后端理解的任何選項。見下一節。
```
--remote=<repo>
```
而不是從本地存儲庫創建tar存檔,從遠程存儲庫中檢索tar存檔。請注意,遠程存儲庫可能會限制`<tree-ish>`中允許哪些sha1表達式。有關詳細信息,請參閱 [git-upload-archive [1]](https://git-scm.com/docs/git-upload-archive) 。
```
--exec=<git-upload-archive>
```
與--remote一起使用以指定遠程端的 _git-upload-archive_ 的路徑。
```
<tree-ish>
```
樹或承諾為其生成存檔。
```
<path>
```
如果沒有可選的路徑參數,則當前工作目錄的所有文件和子目錄都將包含在存檔中。如果指定了一個或多個路徑,則僅包括這些路徑。
## 備用額外選項
### 壓縮
```
-0
```
存儲文件而不是縮小文件。
```
-9
```
最高和最慢的壓縮級別。您可以指定1到9之間的任意數字來調整壓縮速度和比率。
## 組態
```
tar.umask
```
此變量可用于限制tar存檔條目的權限位。默認值為0002,關閉世界寫入位。特殊值“user”表示將使用歸檔用戶的umask。有關詳細信息,請參閱umask(2)。如果使用`--remote`,則只有遠程存儲庫的配置生效。
```
tar.<format>.command
```
此變量指定一個shell命令,通過該命令管道`git archive`生成的tar輸出。該命令是使用shell在其標準輸入上生成的tar文件執行的,并應在其標準輸出上生成最終輸出。任何壓縮級選項都將傳遞給命令(例如,“ - 9”)。如果沒有給出其他格式,則與`<format>`具有相同擴展名的輸出文件將使用此格式。
“tar.gz”和“tgz”格式是自動定義的,默認為`gzip -cn`。您可以使用自定義命令覆蓋它們。
```
tar.<format>.remote
```
如果為true,則啟用`<format>`以供遠程客戶端通過 [git-upload-archive [1]](https://git-scm.com/docs/git-upload-archive) 使用。對于用戶定義的格式,默認為false,但對于“tar.gz”和“tgz”格式,則為true。
## ATTRIBUTES
```
export-ignore
```
具有export-ignore屬性的文件和目錄不會添加到存檔文件中。有關詳細信息,請參閱 [gitattributes [5]](https://git-scm.com/docs/gitattributes) 。
```
export-subst
```
如果為文件設置了export-subst屬性,那么在將此文件添加到存檔時,Git將展開多個占位符。有關詳細信息,請參閱 [gitattributes [5]](https://git-scm.com/docs/gitattributes) 。
請注意,默認情況下,屬性取自正在歸檔的樹中的`.gitattributes`文件。如果您想調整事后生成輸出的方式(例如,您在`.gitattributes`中未添加適當的export-ignore而提交),請根據需要調整簽出的`.gitattributes`文件并使用`--worktree-attributes`選項。或者,您可以在歸檔`$GIT_DIR/info/attributes`文件中的任何樹時保留應該應用的必要屬性。
## 例子
```
git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)
```
創建一個tar存檔,其中包含當前分支上最新提交的內容,并將其解壓縮到`/var/tmp/junk`目錄中。
```
git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip >git-1.4.0.tar.gz
```
為v1.4.0版本創建壓縮的tarball。
```
git archive --format=tar.gz --prefix=git-1.4.0/ v1.4.0 >git-1.4.0.tar.gz
```
與上面相同,但使用內置的tar.gz處理。
```
git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0
```
與上面相同,但是從輸出文件中推斷出格式。
```
git archive --format=tar --prefix=git-1.4.0/ v1.4.0^{tree} | gzip >git-1.4.0.tar.gz
```
為v1.4.0發行版創建壓縮的tarball,但沒有全局擴展的pax標頭。
```
git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ > git-1.4.0-docs.zip
```
將當前頭文檔/目錄中的所有內容放入 _git-1.4.0-docs.zip_ ,前綴為 _git-docs /_ 。
```
git archive -o latest.zip HEAD
```
創建一個Zip存檔,其中包含當前分支上最新提交的內容。請注意,輸出格式是由輸出文件的擴展名推斷的。
```
git config tar.tar.xz.command "xz -c"
```
配置“tar.xz”格式以生成LZMA壓縮的tarfiles。您可以使用它指定`--format=tar.xz`,或創建類似`-o foo.tar.xz`的輸出文件。
## 也可以看看
[gitattributes [5]](https://git-scm.com/docs/gitattributes)
## GIT
部分 [git [1]](https://git-scm.com/docs/git) 套件
- git
- git-config
- git-help
- git-init
- git-clone
- git-add
- git-status
- git-diff
- git-commit
- git-reset
- git-rm
- git-mv
- git-branch
- git-checkout
- git-merge
- git-mergetool
- git-log
- git-stash
- git-tag
- git-worktree
- git-fetch
- git-pull
- git-push
- git-remote
- git-submodule
- git-show
- git-log
- git-shortlog
- git-describe
- git-apply
- git-cherry-pick
- git-rebase
- git-revert
- git-bisect
- git-blame
- git-grep
- gitattributes
- giteveryday
- gitglossary
- githooks
- gitignore
- gitmodules
- gitrevisions
- gittutorial
- gitworkflows
- git-am
- git-format-patch
- git-send-email
- git-request-pull
- git-svn
- git-fast-import
- git-clean
- git-gc
- git-fsck
- git-reflog
- git-filter-branch
- git-instaweb
- git-archive
- git-bundle
- git-daemon
- git-update-server-info
- git-cat-file
- git-check-ignore
- git-checkout-index
- git-commit-tree
- git-count-objects
- git-diff-index
- git-for-each-ref
- git-hash-object
- git-ls-files
- git-merge-base
- git-read-tree
- git-rev-list
- git-rev-parse
- git-show-ref
- git-symbolic-ref
- git-update-index
- git-update-ref
- git-verify-pack
- git-write-tree