[英]How can I use git-archive to include submodules from a bare repository
I'm in the process of setting up a deployment script. 我正在设置部署脚本。 The basic process is:
基本过程是:
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, 如果不可能,我正在考虑,
I use this python package https://github.com/Kentzo/git-archive-all . 我使用这个python包https://github.com/Kentzo/git-archive-all 。 You can install it by using
您可以使用安装它
pip install git-archive-all
On OSX, you can install it also using brew install git-archive-all
在OSX上,您也可以使用
brew install git-archive-all
安装它
If your submodule is in a repo accessible from the server, I would rather have a post-receive hook which would 如果您的子模块位于可从服务器访问的repo中,我宁愿使用post-receive hook
git submodule update --init
) git submodule update --init
旁边的第二个git submodule update --init
),包括子模块( git submodule update --init
) git archive
from 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) git archive
(你肯定会得到正确的版本,因为非裸仓库将引用正确版本的子模块) git archive-all
would be able to detect the .git
subdirectories and would archive everything . git archive-all
将能够检测到.git
子目录和归档会一切 。 If the submodule isn't accessible from the server, that means: 如果无法从服务器访问子模块,则表示:
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" --
Run the following after the regular archive command: 在常规归档命令之后运行以下命令:
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. 这里REPO_ROOT是您的仓库所在的位置,TARGET_ROOT是您存档的版本。 (I assume that you have a TARGET_ROOT folder where the expanded version of the first
git archive
call. If you want a final zip/tar, you can tar/zip the final folder) (我假设您有一个TARGET_ROOT文件夹,其中第一个
git archive
调用的扩展版本。如果您想要最终的zip / tar,您可以tar / zip最终文件夹)
git submodule foreach
provides the $path
variable. git submodule foreach
提供了$path
变量。 See git help submodule
foreach section for more details. 有关更多详细信息,请参阅
git help submodule
foreach部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.