这个post 为您提供了有关以您提到的方式导出 git 的详细信息。
git archive HEAD --format=zip > archive.zip
您还可以使用 --remote= 选项存档远程。只是
请注意,这不适用于 GitHub 遥控器,因为它们
鼓励您改用下载按钮。与任何其他
远程它应该可以正常工作,如果你是,请检查手册页
有问题。
但这种方法的问题是,当我同时使用 github 和 bitbuck 进行尝试时,我得到了remote doesn't support protocol 错误。
我刚刚为我的机器上的通用解决方案编写了代码,它对我有用。让我与你分享。您可以使用shell_exec 使用php 执行shell 命令。
<?php
//clearing a folder named test if it exist(avoiding git errors)
shell_exec('rm -rf test');
//cloning into test folder
shell_exec('git clone https://github.com/nette/sandbox.git test');
//archiving
shell_exec('cd test && git archive HEAD --format=zip > archive.zip');
//copying to root folder
shell_exec('cp test/archive.zip archive.zip');
//removing the temp test folder we created
shell_exec('rm -rf test');
?>
如果打开了 php
safemode,
shell_exec 将不起作用。您可能需要为脚本等设置适当的权限。但我认为这是一个从 php 开始的想法,以获得你想要的。