Windows for 迴圈目錄,執行 git pull?

Windows for 迴圈目錄,執行 git pull?

從 Bash 來看,這很簡單:

for d in *; do GIT_DIR="$d/.git" git pull; done

或者:

for d in *; do GIT_DIR="$PWD/$d/.git" git pull; done

然而,從 Windows 命令提示字元來看,事情就沒那麼簡單了。我試過了:

for /D %i in (*.*) do cd "%i" && git pull
for /D %i in (*.*) do cd "<absolute_path>\%i" && git pull
for /D %i in (*.*) do set GIT_DIR="<absolute_path>\%i\.git git pull"
for /D %i in (*.*) do set GIT_DIR="<absolute_path>\%i\.git && git pull"

但沒有一個有效。總是收到以下錯誤之一:

fatal: unable to access '"repo-name/.git" /config': Invalid argument
The system cannot find the path specified.

答案1

這在 CMD 中的批次文件中對我有用:

for /d %%i in (*.*) do cd %%i & git pull & cd..

答案2

這不是 Powershell 中的簡單一行嗎?

例子:

Resolve-Path D:\work\repos\*\.git | foreach { cd $_; git pull }

答案3

powershell進入瀏覽器位址字段你的基本資料夾按回車鍵。然後執行:

Get-ChildItem . -exclude *.ps1,temp,*.txt | foreach { cd $_; Write-Host "`r`n" $_; Git pull '-v' }

Resolve-Path如果對您不起作用,請使用此方法。

答案4

我建議在具有預設 shell 設定的git pull <repository>Git Shell 上使用語法,並在循環內尋找變數初始化 ( ) 。cmd.exesetlocal enabledelayedexpansionsetfor

相關內容