必要
サーバーが git プロジェクトのグループを変更した後、グループ内のすべての git アドレスが変更され、ローカル git がコードを正常に更新/送信できなくなりました。
git pull実行後にエラーが発生する
GitLab: Project 'old/project' was moved to 'new/project'.
Please update your Git remote and try again:
git remote set-url origin ssh://xxxxx/new/project.git
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
例えば Android プロジェクトはリポジトリで管理し、各ディレクトリはサブ git で管理している 合計で 30 個ほどの git が存在する グループをリモートで変更するとすべての git に影響があり、一つ一つ手動で変更するのは面倒
。
スクリプトを使用して修正する方がはるかに簡単です
成し遂げる
pullall.sh を実行すると、このスクリプトは現在のディレクトリにあるすべての git プロジェクトを走査し、git pull コマンドを実行します。エラーが検出され、URL の変更が原因の場合は、修復するために git remote set-url xxx コマンドが自動的に実行されます。修復が完了したら、再度 git を実行します
。
#!/bin/bash
curdir=`pwd`
for dir in `ls`
do
if [ -d $dir ]; then
echo "-----$dir----"
cd $dir
if [ -d .git ]; then
repair_url=`git pull 2>&1 | grep 'git remote set-url'`
if [ ! "$repair_url" == "" ]; then
echo "---repair:$repair_url--"
$repair_url
echo "git pull"
git pull
fi
fi
fi
cd $curdir
done
著者:イケメンすぎて外出できない