![Windows for-Schleife durch Verzeichnisse, „git pull“ ausführen?](https://rvso.com/image/1444039/Windows%20for-Schleife%20durch%20Verzeichnisse%2C%20%E2%80%9Egit%20pull%E2%80%9C%20ausf%C3%BChren%3F.png)
Von Bash aus ist es einfach:
for d in *; do GIT_DIR="$d/.git" git pull; done
Oder:
for d in *; do GIT_DIR="$PWD/$d/.git" git pull; done
Über die Windows-Eingabeaufforderung ist es jedoch nicht ganz so einfach. Ich habe Folgendes versucht:
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"
Aber nichts davon funktioniert. Ich erhalte immer einen dieser Fehler:
fatal: unable to access '"repo-name/.git" /config': Invalid argument
The system cannot find the path specified.
Antwort1
Bei mir funktioniert das in einer Batchdatei in CMD:
for /d %%i in (*.*) do cd %%i & git pull & cd..
Antwort2
Könnte dies nicht ein einfacher Einzeiler in Powershell sein?
Beispiel:
Resolve-Path D:\work\repos\*\.git | foreach { cd $_; git pull }
Antwort3
Eintreten powershell
inExplorer-AdressfeldIhrerBasisordnerUnddrücke Enter. Führen Sie dann Folgendes aus:
Get-ChildItem . -exclude *.ps1,temp,*.txt | foreach { cd $_; Write-Host "`r`n" $_; Git pull '-v' }
Verwenden Sie diesen Ansatz, wenn Resolve-Path
er für Sie nicht funktioniert.
Antwort4
git pull <repository>
Ich schlage vor , stattdessen die Syntax der Git-Shell mit den Standard-Shell-Einstellungen zu verwenden und innerhalb der Schleife nach der Variableninitialisierung ( ) cmd.exe
zu suchen .setlocal enabledelayedexpansion
set
for