V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
dabao
V2EX  ›  Windows

dos 递归遍历当前目录及子目录,并筛选出指定目录名称的路径,执行 git 命令

  •  
  •   dabao · 2017-06-16 13:16:03 +08:00 · 3328 次点击
    这是一个创建于 2508 天前的主题,其中的信息可能已经有所发展或是发生改变。

    小弟现想通过使用批处理遍历 Windows 中的 D:\Workspace 文件夹下所有文件夹,找到有.git 文件夹的目录,执行 git pull。不知是否可行,请各位赐教!

    希望最好可以贴上批处理代码,谢谢各位兄弟姐妹啦!!!

    8 条回复    2017-06-20 09:09:34 +08:00
    yushiro
        1
    yushiro  
       2017-06-16 13:30:55 +08:00 via iPhone
    你的需求就不是正常的使用 git 流程,想想其他方法吧。
    SourceMan
        2
    SourceMan  
       2017-06-16 13:38:32 +08:00
    可以的,这个需求没问题,也很容易实现,刚好我会写呢
    doublleft
        3
    doublleft  
       2017-06-16 17:06:15 +08:00
    >> 请说出你原始需求 <<

    一键更新所有代码,不管有没有关联?
    我猜测你如果是多个子系统组成的一个系统,可以 submodule 啊
    momocraft
        4
    momocraft  
       2017-06-16 17:11:53 +08:00
    那自然是.. 能

    不过 bash 这种能几行搞定的就算了,cmd 你可能要加钱或等好心人
    guanaco
        5
    guanaco  
       2017-06-16 17:14:55 +08:00
    dir /a /s /d *.git 是要这个?
    geelaw
        6
    geelaw  
       2017-06-16 17:40:02 +08:00 via iPhone   ❤️ 1
    Get-ChildItem '.git' -Directory -Recurse - Force | ForEach-Object {
    Push-Location;
    $_ | Set-Location;
    Set-Location '..';
    # 在这个目录下做你的事情
    Pop-Location;
    }
    nannanziyu
        7
    nannanziyu  
       2017-06-16 17:52:09 +08:00   ❤️ 1
    @echo off
    set pwd=%~dp0
    for /f "delims=" %%i in ('dir /b /a:d /s ".git"') do call:funcPullFolder %%i
    goto:eof

    :funcPullFolder
    cd %~1\..
    git pull
    cd %pwd%
    goto:eof
    dabao
        8
    dabao  
    OP
       2017-06-20 09:09:34 +08:00
    @yushiro @doublleft 谢谢,确实非正常使用,我 clone 了多个 git 项目在本地,每次都要一一更新,太麻烦,于是就想用批处理一次执行获取所有

    @SourceMan @momocraft 谢谢

    @guanaco 谢谢,这命令对我有帮助
    @geelaw 谢谢,这个好像是 powershell 命令吧,在 windows10 下也是非常有用的
    @nannanziyu 谢谢,这个批处理正是我想要的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5047 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 09:44 · PVG 17:44 · LAX 02:44 · JFK 05:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.