Ten examples of git-archive

Git-archive

This command can create an archive of files from a named tree

Basic usages

usage: git archive [<options>] <tree-ish> [<path>...]
   or: git archive --list
   or: git archive --remote <repo> [--exec <cmd>] [<options>] <tree-ish> [<path>...]
   or: git archive --remote <repo> [--exec <cmd>] --list

    --format <fmt>        archive format
    --prefix <prefix>     prepend prefix to each pathname in the archive
    --add-file <file>     add untracked file to archive
    --add-virtual-file <path:content>
                          add untracked file to archive
    -o, --output <file>   write the archive to this file
    --worktree-attributes
                          read .gitattributes in working directory
    -v, --verbose         report archived files on stderr
    -NUM                  set compression level

    -l, --list            list supported archive formats

    --remote <repo>       retrieve the archive from remote repository <repo>
    --exec <command>      path to the remote git-upload-archive command

Examples

  1. Create a single snapshot of your project so you can send the resulting archive to a client for review or create git-independent backups of important revisions.

    git archive master --format=tar --output=../name_what_you_want.tar
  2. Create a tar archive that contains the contents of the latest commit on the current branch, and extract it in the /var/tmp/junk directory.

    git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)

    References:
    Piping in Unix or Linux - GeeksforGeeks
    Linux Double Ampersand - javatpoint
    bash - How are parentheses interpreted at the command line? - Unix & Linux Stack Exchange
    tar(1) [osx man page]

  3. Create a compressed tarball for v1.0 release.

    git archive --format=tar --prefix=git-1.0/ v1.0 | gzip >git-1.0.tar.gz

    References:
    gzip(1) [osx man page]

  4. Same as above, but using the builtin tar.gz handling.

    git archive --format=tar.gz --prefix=git-1.0/ v1.0 >git-1.0.tar.gz
  5. Same as above, but the format is inferred from the output file.

    git archive --prefix=git-1.0/ -o git-1.0.tar.gz v1.0
  6. Create a compressed tarball for v1.4.0 release, but without a global extended pax header.

    git archive --format=tar --prefix=git-1.0/ v1.0^{tree} | gzip >git-1.0.tar.gz

    References:
    For v1.0^{tree}, refer to: Git - gitrevisions Documentation
    Git - git-get-tar-commit-id Documentation

  7. Put everything in the current head’s Documentation/ directory into git-about.zip, with the prefix git-about/.

    git archive --format=zip --prefix=git-about/ HEAD:about/ > git-about.zip

    References:
    HEAD:about/
    Git - revisions Documentation

  8. Create a Zip archive that contains the contents of the latest commit on the current branch. Note that the output format is inferred by the extension of the output file.

    git archive -o latest.zip HEAD

    References:
    unzip(1) - Linux man page

  9. Creates a tar archive that contains the contents of the latest commit on the current branch with no prefix and the untracked file configure with the prefix build/.

    git archive -o latest.tar --prefix=build/ --add-file=configure --prefix= HEAD
  10. Configure a “tar.xz” format for making LZMA-compressed tarfiles. You can use it specifying --format=tar.xz, or by creating an output file like -o foo.tar.xz.

    git config tar.tar.xz.command "xz -c"
    git archive -o latest.tar.xz HEAD

    References:
    How to Extract (Unzip) tar.xz File | Linuxize
    Git - git-archive tar.<format>.command Documentation

本作品采用《CC 协议》,转载必须注明作者和本文链接
日拱一卒
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
93
粉丝
85
喜欢
153
收藏
121
排名:71
访问:11.4 万
私信
所有博文
社区赞助商