从批处理(.bat)文件运行带有竖线的git.exe命令
我想使用以下命令从*.bat文件中删除所有git本地分支(主分支除外):从批处理(.bat)文件运行带有竖线的git.exe命令,git,batch-file,Git,Batch File,我想使用以下命令从*.bat文件中删除所有git本地分支(主分支除外): git.exe branch | grep -v "master" | xargs git branch -D 但该字符串包含“|”,命令失败 也不起作用: git.exe "branch | grep -v "master" | xargs git branch -D" 及 根据给出的答案,您可以执行如下批处理脚本: @echo off REM -- Variable declerations set "textF
git.exe branch | grep -v "master" | xargs git branch -D
但该字符串包含“|”,命令失败
也不起作用:
git.exe "branch | grep -v "master" | xargs git branch -D"
及
根据给出的答案,您可以执行如下批处理脚本:
@echo off
REM -- Variable declerations
set "textFile=tempBranchInfo.txt"
set "branchToKeep=master"
set "branchToReplaceWith="
git checkout master
git branch > %textFile%
REM -- remove "master" from list to keep the branch
for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
set "line=%%i"
setlocal enabledelayedexpansion
>>"%textFile%" echo(!line:%branchToKeep%=%branchToReplaceWith%!
endlocal
)
REM -- execute branch delete commands
for /f "delims=" %%a in (%textFile%) do (
git branch -D %%a
)
REM -- remove temp-file with branch information inside
DEL %textFile%
REM -- show local branches after the cleaning
echo Local branches:
git branch
pause
exit
它将使用一个临时文件来存储要删除的分支的名称。我使用git alias解决了这个问题
[alias]
dellocbr = !sh -c \"git branch | grep -v \"master\" | xargs git branch -D\" -
批量运行:
git dellocbr
命令如何失败?您看到了什么错误消息?
git dellocbr