各位好,本人想用一個簡單的shell script
來讓某目錄下的多個submodule,並在其中執行git checkout (commit SHA)
及 git restore .
目前想到的大概是這樣,才後會用多個if來找我要的submodule:
for item in /path/to/submodule/*;do
if [${item} == 'name'];then
git restore .
git checkout (commit SHA)
fi
done
然而 if[${item} == 'name'] 這不要怎麼寫才對
我希望name對應到的是路徑最右邊的item
先謝謝各位看完問題了,因為很少寫shell所不太會問,不清楚的地方我會再補充
不是下 git submodule update 嗎?
作者:
lantw44 (#######################)
2023-01-27 18:31:00if [ "${item}" = name ] 所有的空格都不能省略。不過應該不用自己寫 for,可以用 git submodule foreach
作者:
drm343 (一卡)
2023-01-27 20:47:00這個我第一個想到的也是 git submodule foreach
會問這個是因為submodule很多,而且每個submodule都會用一個特定的commit,這可能只能用git checkout來做。有時候因為不明原因,某幾個submodule的commit會跑掉,要再手動一個個調回很費時
作者:
lantw44 (#######################)
2023-01-28 19:57:00你可以把 if 那段寫在給 foreach 執行的 script 裡。