V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
hackpro
V2EX  ›  Apple

分享一条命令可批量更新一个目录下的 git repository

  •  
  •   hackpro · Dec 13, 2016 · 3199 views
    This topic created in 3430 days ago, the information mentioned may be changed or developed.
    find . ! -path . -maxdepth 1 -type d | xargs -L 1 bash -c 'cd "$0" && pwd && git pull'
    

    主要是先枚举目录下的目录(记得去掉当前目录) 然后利用 xargs 进行处理

    7 replies    2016-12-14 00:55:23 +08:00
    slixurd
        1
    slixurd  
       Dec 13, 2016
    ls | xargs -I {} bash -c 'cd {} && pwd && git status'
    这样也是一样的啊= =....
    leopku
        2
    leopku  
       Dec 13, 2016
    改进

    find . ! -path . -maxdepth 1 -type d | xargs -L 1 bash -c 'cd "$0" && pwd && git reset HEAD --hard && git fetch && git pull'
    xjp
        3
    xjp  
       Dec 13, 2016 via iPhone
    给楼上的所有分享一个知识点 git 可以指定操作目录的 不需要 cd 过去的
    billlee
        4
    billlee  
       Dec 13, 2016
    @slixurd 你这个只适用于 $PWD 下只有目录的情况
    hackpro
        5
    hackpro  
    OP
       Dec 13, 2016
    @leopku
    @slixurd
    @xjp
    @billlee

    顺便请教下 如果这个命令要写成 alias 放在 .zshrc 中的话
    比如 alias upgrade_git="..."
    如何处理命令中本来有的双引号,即 cd "$0"
    binarylu
        6
    binarylu  
       Dec 14, 2016
    推荐楼主一个工具: http://fabioz.github.io/mu-repo/ (虽然我并不喜欢他,无奈公司强制使用)
    billlee
        7
    billlee  
       Dec 14, 2016
    @hackpro bash 里是可以 blackslash \ 转义的, zsh 没试过,应该查不多吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   925 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 18:29 · PVG 02:29 · LAX 11:29 · JFK 14:29
    ♥ Do have faith in what you're doing.