• 使用bat脚本部署hexo到coding和github


    因项目的不同适当的改造吧,本文以hexo为例。

    拉取coding.net的代码和github的代码到本地

    1. 确保代码能够正常的运行,commit,push
    2. 在项目的目录外新建一个push.bat文件

    快速预览

    如何一步到位提交到仓库

    脚本中的变量说明

    • artsPath 新增文章的目录
    • codingPath coding的目录
    • githubPath github的目录

    复制文章然后自动执行命令进行部署

    修改脚本中对应的路径后执行push

    xcopy F:CodingReposymhexoarts F:CodingReposymhexoyimocodingsource\_posts /Y
    cd F:CodingReposymhexoyimocoding
    call git pull
    call hexo clean
    call hexo d -g
    call git add *
    call git commit -m AddArticle
    call git push
    

    优化v1-加入变量并读取第一个参数为注释

    查阅了果然cmd是有变量的,所以提前了路径到变量中,注释也可以传入了
    使用push 修改文章,提交之后注释为update_修改文章,可省略参数

    set artsPath=F:CodingReposymhexoarts
    set codingPath=F:CodingReposymhexoyimocoding
    set githubPath=F:CodingReposymhexoyimogit.github.io
    
    xcopy %artsPath% %codingPath%source\_posts /Y
    cd /d %codingPath%
    call git pull
    call hexo clean
    call hexo d -g
    call git add *
    call git commit -m update_%1
    call git push
    

    优化v2-多个仓库的部署

    复制粘贴是最简单的了,but~ 我感觉还能再优化下
    定义变量,然后保存到字符串str中,通过赋值str后调整到for取下一个值实现一个路径的先入先出的T_T【笑哭】可以算作循环数组的方法了

    
    @echo off
    set artsPath=F:CodingReposymhexoarts
    REM coding的目录
    set codingPath=F:CodingReposymhexoyimocoding
    REM github的目录
    set githubPath=F:CodingReposymhexoyimogit.github.io
    REM 默认注释add_article,第一个参数为注释
    set notes=%1 
    if "%1"=="" set notes=add_article
    REM 拼接coding和github的目录地址,路径中不能含有空格
    set str="%codingPath% %githubPath%"
    
    :STR_START
    for /f "tokens=1,*" %%a in (%str%) do (
        REM 复制文章到此仓库
        xcopy %artsPath% %%asource\_posts /Y
        REM 重定向到此仓库
        cd /d %%a
        REM 更新推送等操作
        call git pull
        call hexo clean
        call hexo d -g
        call git add *
        call git commit -m %notes%
        call git push
        REM 重新将新字符串赋值个str,并重新开时循环新的字符串
        set str="%%b"
        goto STR_START
    )
    
    

    过去过不去的都会过去

    不愿干重复的事情~
    就是如此的懒~
    能一个脚本干完所有事简直完美~
    不知道有没有比这种方法更好的实现

  • 相关阅读:
    [LUOGU] P2196 挖地雷
    [LUOGU] P1020 导弹拦截
    [LUOGU] P2543 [AHOI2004]奇怪的字符串
    [LUOGU] P2759 奇怪的函数
    [LUOGU] P1048 采药
    [LUOGU] P1396 营救
    [LUOGU] P1196 [NOI2002]银河英雄传说
    [LUOGU] 2820 局域网
    知识点
    swich使用
  • 原文地址:https://www.cnblogs.com/morang/p/cmd-batch-pull-git.html
Copyright © 2020-2023  润新知