【问题标题】:Git export achive directly from originGit直接从原点导出
【发布时间】:2015-01-03 14:51:07
【问题描述】:

我想创建一个简单的脚本,它将插件从远程存储库下载到目录中。我有一组 URL,用于远程服务器上的 git 文件 - 就像来自 GitHub https://github.com/nette/sandbox.git 的这个。 GitHub 支持下载 ZIP 档案,但我有来自许多其他存储库的插件,它们不提供此选项。

回到我的问题 - 是否有任何选项如何获取存档而不是下载完整的存储库并在命令行中使用 git 从其中导出存档?我发现了这个问题 - Do a "git export" (like "svn export")? - 但是使用 PHP 是不可能的。

【问题讨论】:

    标签: php git zip archive


    【解决方案1】:

    这个post 为您提供了有关以您提到的方式导出 git 的详细信息。

    git archive HEAD --format=zip > archive.zip

    您还可以使用 --remote= 选项存档远程。只是 请注意,这不适用于 GitHub 遥控器,因为它们 鼓励您改用下载按钮。与任何其他 远程它应该可以正常工作,如果你是,请检查手册页 有问题。

    但这种方法的问题是,当我同时使用 githubbitbuck 进行尝试时,我得到了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 开始的想法,以获得你想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-11
      • 2018-12-03
      • 2012-07-28
      • 2013-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多