![Windows for 迴圈目錄,執行 git pull?](https://rvso.com/image/1444039/Windows%20for%20%E8%BF%B4%E5%9C%88%E7%9B%AE%E9%8C%84%EF%BC%8C%E5%9F%B7%E8%A1%8C%20git%20pull%EF%BC%9F.png)
從 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.exe
setlocal enabledelayedexpansion
set
for