bash - 除了移动到每个目录之外,是否有 git 或 bash 方式来提取多个 git 存储库?

标签 bash git

我编写了这个(强力)脚本,使多个存储库保持最新状态。

for app in $(/bin/ls  -d $@)
do
  cd $app
  pwd
  git pull
  cd ..;
done

请问有更简单的方法吗?

最佳答案

您至少可以简化脚本:

  1. Don't parse ls
  2. 使用for x instead of for x in "$@"
  3. 使用 subshellavoid cd-ing out

并避免错误:

  1. Quote your args
  2. cd 上使用 -- 以避免参数被解释为选项
  3. Skip the loop if cd fails
for app; do
    (
        cd -- "$app" || continue
        pwd
        git pull
    )
done

顺便说一句Shellchek是调试 shell 脚本的重要资源。我在那里得到了大部分提示。

关于bash - 除了移动到每个目录之外,是否有 git 或 bash 方式来提取多个 git 存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57367221/

相关文章:

git - 用原始仓库中的内容强制覆盖本地文件?

git - git status 和 git diff --name-only 有什么区别?

git - git 裸存储库中的 "fetch --all"不会将本地分支同步到远程分支

linux - 如何找到文件中最低值的位置?

bash - SQLite插入的bash循环错误

linux - Unix:遍历一个目录

java - JGit 设置 git : URI instead of https: for remote on CircleCI

git - 如何从 jenkins 登录到 git bitbucket 存储库

c++ - 从任何目录运行 C++ 程序

regex - Python Fabric - 在带空格的目录中删除与模式匹配的文件?