duansen6750 2015-01-03 14:51
浏览 43

Git直接从原产地出口

I would like to create a simple script, that will download plugins from remote repositories into directory. I have an array of URLs, to git files on remote server - like this one from GitHub https://github.com/nette/sandbox.git. GitHub has support for downloading ZIP archives but I have plugins from many other repositories which doesn't offer this option.

Back to my question - is there any option how to get the archive instead of downloading full repository and exporting archive from it using git in command line? I have found this question - Do a "git export" (like "svn export")? - but this wouldn't be possible using PHP.

  • 写回答

1条回答 默认 最新

  • duanpu4143 2015-01-03 18:43
    关注

    this post gives you details about exporting git in the way you mentioned .

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

    You can also archive a remote using the --remote= option. Just be aware that this does not work with GitHub remotes, as they encourage you to use the download button instead. With any other remote it should work fine though, and check the manpage if you’re having issues.

    but the problem with this method is when i tried it with both github and bitbuck i got remote doesn't support protocol error .


    i just wrote code for a generic solution on my machine and its working for me . let me share it with you . you can execute shell command using php using shell_exec .

    <?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');
    
    ?>
    

    shell_exec won't work if php safemode is turned on . you might require setting appropriate permissions for the script etc . but i think this an idea to start with php, for getting what you want.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度