gpt4 book ai didi

git - 在 bash 脚本中运行 git commit for loop for multiple repos

转载 作者:行者123 更新时间:2023-12-04 18:01:45 24 4
gpt4 key购买 nike

我正在尝试编写一个脚本来简化我的批量 - git 协作,以便一次推送/pull/或提交多个 git 项目。

我在多个网站上工作,我想一次 pull 所有网站的所有当前更改。

这是我的。

#!/bin/bash -e

REPOS=(
/Users/me/repo1
/Users/me/repo2
/Users/me/repo3
)

echo push, pull or commit?

read input

if [$input -eq "commit"]
then
for i in “${REPOS[@]}”
do
cd $i
git add . -A
git commit -m "auto commit backup point"
echo "Moving to Next REPO...
"
sleep 2
done

else
for i in “${REPOS[@]}”
do
cd $i
git $input
echo "Moving to Next REPO...
"
sleep 2
done
fi

现在,当脚本提示我输入时,推或 pull 工作正常(某种程度上),脚本运行所有站点并相应地 pull 或推。

然而,当我响应“commit”时,脚本会遍历每个 repo,但提交无法正常工作。 Commit 消息提示在 vi 中打开,这不是首选,并且没有提交。如果我导航到任何存储库,仍然会有阶段性更改。

任何输入将不胜感激。

最佳答案

if [$input -eq "commit"] 缺少空格。将其重写为 if [ $input -eq "commit"]。否则它会转到 else 条件并执行 git $input,其中 input=commit。

哦,是的,-eq 用于整数,应该是 if [ $input = "commit"]

关于git - 在 bash 脚本中运行 git commit for loop for multiple repos,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34244409/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com