如何使用 git-archive 从裸存储库中包含子模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5482544/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:15:10  来源:igfitidea点击:

How can I use git-archive to include submodules from a bare repository

gitdeploymentgit-submodulesgit-bare

提问by Jacob

I'm in the process of setting up a deployment script. The basic process is:

我正在设置部署脚本。基本流程是:

  1. Push changes to a bare repository on the server
  2. Then based on new tags will create a new folder for the release.
  3. Use git archive to move the files into the release directory
  4. Runs some migrations scripts and puts it live (if all is successful).
  1. 将更改推送到服务器上的裸存储库
  2. 然后基于新标签会为发布创建一个新文件夹。
  3. 使用 git archive 将文件移动到发布目录
  4. 运行一些迁移脚本并使其生效(如果一切成功)。

The issue is my repository contains a submodule, which doesn't get put in the archive, and therefore doesn't get put in the release directory.

问题是我的存储库包含一个子模块,它没有放在存档中,因此没有放在发布目录中。

I've seen git-archive-all, but that doesn't work on a bare repository.

我见过git-archive-all,但这不适用于裸存储库。

If its not possible, I'm considering,

如果不可能,我正在考虑,

  1. making the repository not bare, and updating the working copy, which would allow me to use git-archive-all. Or
  2. having a second bare repository of the submodule on the server, which I could get an archive from (would have to look into this to make sure I'm getting the right revision).
  1. 使存储库不是空的,并更新工作副本,这将允许我使用 git-archive-all。或者
  2. 在服务器上有第二个子模块的裸存储库,我可以从中获取存档(必须查看此内容以确保我获得正确的修订版)。

采纳答案by VonC

If your submodule is in a repo accessible from the server, I would rather have a post-receive hook which would

如果您的子模块位于可从服务器访问的存储库中,我宁愿有一个接收后挂钩

  • update a full non-bare repo (so a second repo beside your original bare one), including the submodule (git submodule update --init)
  • git archivefrom that second repo (you would be sure to get the right version since the non-bare repo would reference the right version of the submodule)
    Since the non-bare repo would contain the parent repo andits submodules, git archive-allwould be able to detect the .gitsubdirectories and would archive everything.
  • 更新一个完整的非裸仓库(所以在你原来的裸仓库旁边是第二个仓库),包括子模块 ( git submodule update --init)
  • git archive从第二回购(你将来一定会得到正确的版本,因为非裸露的回购协议将引用子模块的正确版本)
    由于非裸露的回购协议将包含母公司回购它的子模块,git archive-all就能够检测.git子目录,并将存档所有内容

If the submodule isn't accessible from the server, that means:

如果无法从服务器访问子模块,则意味着:

  • it needs to be pushed in its own repo on the server
  • the submodule in the parent repo needs to be reference with a relative path, in order for the parent repo to still be able to retrieve said submodule once pushed on the server.
  • 它需要被推送到服务器上自己的仓库中
  • 父存储库中的子模块需要使用相对路径进行引用,以便父存储库在推送到服务器后仍然能够检索所述子模块。

回答by ismailsunni

I use this python package https://github.com/Kentzo/git-archive-all. You can install it by using

我使用这个 python 包https://github.com/Kentzo/git-archive-all。您可以使用安装它

pip install git-archive-all

On OSX, you can install it also using brew install git-archive-all

在 OSX 上,您也可以使用安装它 brew install git-archive-all

回答by Brandon

回答by Tobu

Here it is as a few-liner:

这是几行:

prefix=$(basename "$(pwd -P)")
{
  git ls-files
  git submodule foreach --recursive --quiet \
                'git ls-files --with-tree="$sha1" | sed "s#^#$path/#"'
} | sed "s#^#$prefix/#" | xargs tar -c -C.. -f "$prefix.tar.xz" --

回答by Cagdas Tulek

Run the following after the regular archive command:
git submodule foreach 'cd REPO_ROOT/$path && git archive HEAD | tar -x -C TARGET_ROOT/$path'

在常规存档命令之后运行以下命令:
git submodule foreach 'cd REPO_ROOT/$path && git archive HEAD | tar -x -C TARGET_ROOT/$path'

Here the REPO_ROOT is where your repo stands and the TARGET_ROOT is where you put your archived version. (I assume that you have a TARGET_ROOT folder where the expanded version of the first git archivecall. If you want a final zip/tar, you can tar/zip the final folder)

此处 REPO_ROOT 是您的存储库所在的位置,而 TARGET_ROOT 是您放置存档版本的位置。(我假设你有一个 TARGET_ROOT 文件夹,其中第一次git archive调用的扩展版本。如果你想要最终的 zip/tar,你可以 tar/zip 最终文件夹)

git submodule foreachprovides the $pathvariable. See git help submoduleforeach section for more details.

git submodule foreach提供$path变量。有关git help submodule更多详细信息,请参阅foreach 部分。