Git 归档没有目录路径的目录

Git archive a directory without the directory path

我找到了一些关于如何使用 7zip cli 执行此操作的参考资料: https://superuser.com/questions/340046/create-an-archive-from-a-directory-without-the-directory-name-being-added-to-the?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa#

但具体来说,我想使用 git archive 创建一个子目录的 zip 文件,但我希望存档不包含子目录名称作为顶级文件。

我得到的最接近的是: git archive --format zip HEAD ./dist/* > deploy.zip

但它会生成一个 zip 文件,其父目录名为 dist/

我的文件夹结构是这样的;

project
  - .git
  - src
  - dist
    - my files and folders

我想做的是只归档 "dist" 目录及其所有内容在生成的归档文件的顶层。

来自 git-archive documentation (*):

git archive --format zip HEAD:dist/ > deploy.zip

本质上 tree-ish 可以有格式 <rev>:<path>

*:来自 git 文档的示例启发了答案是“将当前 head 的 Documentation/ 目录中的所有内容放入 git-1.4.0-docs.zip,前缀为 git-docs/"