如何使用 git-archive 包含裸存储库中的子模块?
我正在设置部署脚本。基本流程是:
- 将更改推送到服务器上的裸存储库
- 然后基于新标签将创建一个用于发布的新文件夹。
- 使用 git archive 将文件移动到发布目录
- 运行一些迁移脚本并将其投入使用(如果一切成功)。
问题是我的存储库包含一个子模块,该子模块不会放入存档中,因此不会放入发布目录中。
我见过 git-archive-all,但这在裸存储库上不起作用。
如果不可能,我正在考虑
- 使存储库不裸露,并更新工作副本,这将允许我使用 git-archive-all。或者
- 在服务器上有子模块的第二个裸存储库,我可以从中获取存档(必须对此进行研究以确保我获得正确的修订版)。
I'm in the process of setting up a deployment script. The basic process is:
- Push changes to a bare repository on the server
- Then based on new tags will create a new folder for the release.
- Use git archive to move the files into the release directory
- Runs some migrations scripts and puts it live (if all is successful).
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.
If its not possible, I'm considering,
- making the repository not bare, and updating the working copy, which would allow me to use git-archive-all. Or
- 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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
基于此处的答案和评论。您可以创建非裸存储库并运行:
--verbatim-files-from
--xform s: ^:prog/:
完整版:
Based on answers and comments here. You can create non-bare repo and run:
--verbatim-files-from
--xform s:^:prog/:
Full version:
我使用这个 python 包 https://github.com/Kentzo/git-archive-all。您可以使用 OSX 上的命令来安装它
,也可以使用
brew install git-archive-all
来安装它I use this python package https://github.com/Kentzo/git-archive-all. You can install it by using
On OSX, you can install it also using
brew install git-archive-all
如果您的子模块位于可从服务器访问的存储库中,我宁愿有一个接收后挂钩,它将
git子模块更新 --init
)git archive
(您一定会获得正确的版本,因为非裸存储库将引用子模块的正确版本)由于非裸存储库将包含父存储库及其子模块,因此
git archive-all
将能够检测.git
子目录并将存档所有内容。如果子模块无法从服务器访问,则意味着:
If your submodule is in a repo accessible from the server, I would rather have a post-receive hook which would
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)Since the non-bare repo would contain the parent repo and its submodules,
git archive-all
would be able to detect the.git
subdirectories and would archive everything.If the submodule isn't accessible from the server, that means:
这应该可以解决问题: https://github.com/meitar/git-archive -all.sh/wiki
This should do the trick: https://github.com/meitar/git-archive-all.sh/wiki
这是几行:
Here it is as a few-liner:
我的案例构建系统依赖 git 来了解它构建的源代码的版本。
为了创建完整 git 树的非常小的存档保留 git,我使用了
提示 -只有超级大的存储库才需要深度超长的历史或大量的大文件。就我而言,浅克隆有助于将 .git 包的大小从 2.5GB 减小到 94MB,
然后从工作树中删除文件,除了
.git
fd 可能是通过
apt install fd-find
安装,也可以使用默认的utilfind
或bash的extglob
下一步压缩解
压缩
现在所有工作树都是在实际状态下。
使用
--depth 1
你总是只有一个分支和唯一的一次提交。最后要注意的是,
不可能一次克隆仓库裸露和递归,因为子模块 git 需要实际的工作树。
--recurse-submodules[=]
创建克隆后,根据提供的路径规范初始化并克隆其中的子模块。如果没有路径规范
前提是,所有子模块都被初始化和克隆。对于由以下组成的路径规范,可以多次给出此选项
多个条目。生成的克隆将 submodule.active 设置为提供的路径规范或“。” (指所有子模块)如果
没有提供路径规范。
I my case build system relies on git to know version of source code it builds from.
To create a very minimal archive of full git tree keeping git i used
hint --depth is required for only super big repos with super long history or with amount of big files. in my case shallow cloning helps to reduce size of .git pack from 2.5GB to 94MB
then remove files from worktree except
.git
fd could be installed via
apt install fd-find
, also can use default utilfind
or bash'sextglob
next step compress
uncompress
now all worktree is in actual state.
with
--depth 1
you always will have only one branch with the only one commit.last note
there is no possibility to clone repo bare and recursive at a time, for submodules git requires actual worktree.
--recurse-submodules[=<pathspec>]
After the clone is created, initialize and clone submodules within based on the provided pathspec. If no pathspec is
provided, all submodules are initialized and cloned. This option can be given multiple times for pathspecs consisting of
multiple entries. The resulting clone has submodule.active set to the provided pathspec, or "." (meaning all submodules) if
no pathspec is provided.
在常规归档命令之后运行以下命令:
git submodule foreach 'cd REPO_ROOT/$path && git 归档头 | tar -x -C TARGET_ROOT/$path'
这里 REPO_ROOT 是您的存储库所在的位置,TARGET_ROOT 是您放置存档版本的位置。 (我假设您有一个 TARGET_ROOT 文件夹,其中包含第一个 git archive 调用的扩展版本。如果您想要最终的 zip/tar,可以 tar/zip 最终文件夹)
git 子模块foreach 提供
$path
变量。有关更多详细信息,请参阅每个部分的git help submodule
。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. (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)git submodule foreach
provides the$path
variable. Seegit help submodule
foreach section for more details.