批处理脚本Windows .bat文件中删除部分String

问题描述 投票:0回答:0

我正在创建用于在 GitFlow 中删除 Git 上的旧分支的批处理脚本。您只需输入发布分支,所有旧的发布分支都会从远程删除,(目前只有

echo
用于测试目的)。 “旧分支”由
/
ex 后面的版本号确定。
release/1.15
。我目前正在使用仅适用于发布
1.xx
的变体,但我被卡住了,因为
git ls-remote
也返回给定分支的散列,而且我无法将其从变量中删除,因此比较不会辞掉工作

任何想法如何摆脱它?

@echo off
setlocal enabledelayedexpansion

set /p CUTOFF_BRANCH=Enter the name of the release branch:
set CUTOFF_BRANCH_VERSION=!CUTOFF_BRANCH:release/1.=!

for /f "tokens=*" %%a in ('git ls-remote --heads origin "release/*"') do (
    set BRANCH_REF=%%a
    set BRANCH_NAME=!BRANCH_REF:refs/heads/=!
    set BRANCH_NAME_VERSION=!BRANCH_NAME:release/1.=!
    echo !CUTOFF_BRANCH_VERSION!   !BRANCH_NAME_VERSION! >> output.txt
    if "%BRANCH_NAME_VERSION%" lss "%CUTOFF_BRANCH_VERSION%" (
        echo ref !BRANCH_REF! >> output.txt
        echo deleting !BRANCH_NAME! >> output.txt
    )
)
echo All older release branches have been deleted.

pause

输出.txt

120   f16eed16b2a101cd06b106f2ac81af85199609d4     0 
120   7045e4dd3171d93c47c4f5cc8cb30c4fe19d50a5     1 
120   7d2b03e8152fe808869bde89dfcd023cfc5e3b5b     10 
120   175938e52575d02124827494adf81c15de967f05   100 
120   a80aa3c4a3b4f3b57bee6e6008a347737f01a618    101 
120   c41c0c0d6c6f4c8d09a68b15f5bb9c4bf9ad4fbb       102 
120   3aea2f17a0365b25f3a4565a0871e55237f917c0     103 
120   82aa2bad9fc099e4e3ce95c9774d44d2c21ae316    104 
120   decf20a91aaa779ca9a9c19d29deb74ad0e3c678    105 
120   52b4b3ddb5284be7d2db54a479ce21603c0cdb40  106 
120   bd50152bfa0e94889bce40f6c8f9a9713903c551     107 
120   c75986b78b82860dc15873a1adf2b20139f86310    108 
120   01d5f973dc1ae5d668f3ee5209f326cac81db153     109 
120   d5e6f7337e9bf5a0123420ce9b56b516de2bfa77    11 
120   3ad9e27aba5dd201a94835c47a3ebfed6de8ef5c    110 
120   2f7fe3552bda118944f4eb35359a37b9468a4142    111 
120   8e69e89ff3003a2d2e4bbffd62dc2e2d89df13da      112 
120   b577674b3447d0ba2d3d99b88ec7175072419aa0 113 
120   da9f8a4b7f798030caf34130f01feee90d79a330       114 
120   e3929f65277f09789bd72c8efff2e67f38a8adfb        115 
120   7c35ad8ccf90982511bb34c2e6b920d287a28cfa     116 
120   adab8446e257d40a93635a1446744568c9f86ae4   117 
120   17419dfac20d38d0989448b398851363d2682ab1  118 
120   6bb85dd1f15498f72c3a83eeae92afa76315a823     119 
120   a1422be7fe0a2da27b9182ff621db8c1e7f8eeec      12 
120   f1af94198c7000f69b90ab8533a1e0c43a7a680e     120 
120   3f80559ee7d47d0c673a47b20004ff6fb3cda3a4      121 
120   77451d142ad13f2ca9d12267f653b9c8796063a7    122 
120   7f0613c124a2c8115fa49b12629f277a484da631     123 
120   5e7aef54eb2812bc97898f3a0fc45c8b4040e7e6     124 
120   b32ce4cd15c28cca09bc6a0bf9475cd8f1312b5b      125 
120   41583d3d2ae94d365020b2a97d84786a94e7d78a                126 
120   7253b1ad454678d023fff1a886df53b7da8498ce     127 
120   878e37f2278b7d01dab604ffda9de42be18ec36b    128 
120   cd975c059c4b88c9f15d7b57008ccb462440933e    129 
120   4403b59d56cc9f693809b600948e6fe066fbbe29    13 
120   370f262081d65e1396ba051537fc136f165a8eee     14 
120   19e75334a29574874ceac9dc5769e8f0c44b15d3    15 
120   8796b1c6c5aa8d01c03975307d8df912a9cc4625    16 
120   39901018838834155b2d37e3d7192ff6cf583cbf     17 
120   30c59f7eea70f0177f40ca05cff0e2cd21944b30        18 
120   e1499c852178b7a38baea81735aed4c5ccdff838     19 
120   dc3287b663f121a8f9eed93eb235a018a88e3488    2 
120   afae47609d2bbd5ff783905a308a1862ffefa6a0       20 
120   d0c1740b11dd6075f9e890d3711f8cb58fcac4c8     21 
120   d4aaa4273f9c4316b23b2668afbd7ce426eb2ce5    22 
120   044c508dacfd174930909ce720241c375ce7b839    23 
120   184b55dd5b32ab10cae6593066112c4b5e006dde  24 
120   9f824c58ccbaccd363ac437bce328a5f626c7d4b      25 
120   81ff4bdd15b1581be2dd6c755840d8ed265699e5   26 
120   a46cd8d6606de45680464cafe05d455c77634ca6    27 
120   ed757a704d70b7dd244af734d0886fd7bdfe0833    28 
120   f8bd9119374c9583219be5dd75ab85407fb3f6db    29 
120   6c7ca9825fe3c7e4cf298e701d2cbe969f6412d0      3 
120   513fd0a2d4556eead6155751c152d07da78424ca   30 
120   4dc7149a21b7e5d9a1b995d02bc8d0d37f9f7b21   31 
120   537e3e9228a067b91be3ed3bba41bce3230c4d13  32 
120   4d317b7499b2469168ffe84adcd744cff540a108      33 
120   dcdc616f6fb6c059905a1be7d469c06f996fdeac       34 
120   31b6c480a18f7449fc127e23758b9e2817db5f33     35 
120   6ec1b27e336bcfd64c65fd82d83d959ce055b7e4    36 
120   3a9f1a00106c7ee226db9768c2566da288cdeb05   37 
120   df321b22afd4aeeb540ddc56393a7330efedb778    38 
120   cfca958589b51fa9a40381d45c98e9b64130242c     39 
120   5e573d92da55971ee1d7159ce2bd76ec4df1632b   4 
120   8db409da6b4c4bb7c9b2074d7184f34a496af60d    40 
120   8458f8df4c204e2bab87d4163f566c62cc27d954     41 
120   59055ee34f291510ebacd284c571d57e02df1457    42 
120   ef74bac338239d5b8da79d490945ba2859257fb9   43 
120   6b50756a5a15ad2940100d27ab9674aada694954  44 
120   37eed0379d89934e9921323c138973895368cf82   45 
120   030c896f941b5574be651bdd45ab6d1b896e0540  46 
120   d29c8793a9de7537b5f034b72db267ed5fd3d412   47 
120   7e9df5dd4669cf5b7241b9cafb108ab8bee5392a     48 
120   9710adf26e25925a1b4a46b8d17ba91eb47633f7   49 
120   7a89cff030a0c08a3811af8e200a3562c1dc2021      5 
120   6fb81e3b88ceea07306eff1336a697eb802c8249     50 
120   72091e96c98fd821c801160b73b1a5463eecb37c    51 
120   175f39a565cdf443ccdd7d113a6c74462adfa958      52 
120   f73de829287ccff3027a447fc41dc3884ab1f8b6       53 
120   0ca7e0f42c5ea7d6bb308c2786a61faaff3aeb37       54 
120   9d66c74fb15597631e478e97a97d56e66b3c3a56   55 
120   942b88f1ad40c65194c15420405d8bc78c47e812    56 
120   e1267d0aae49710bc318644edc83cf80ed32a5ae    57 
120   b64259d42af508c87fe965913d81f04e5e203976    58 
120   08bb21fb3bb4cd1ff9651e54ee4cfed11cf3b424       59 
120   cb4996a4f130bf867ffed0c46fa2a8df2047e45e        6 
120   72619264fa2c0882aa8a443fc3e5692f4d9d5f5b      60 
120   f3158436708148d358d6b1582a5a95fad9a0f2e7    61 
120   6eb58e6ccc4fa80afbb57034dd3eca5462e852bc     62 
120   0bd583089cb08ceb649c0aaa073b294190fdb083   63 
120   da3bd8391b0c38df871b727ebcd8d0cce2d8a2d9   64 
120   f9c33c9e4a2a99ce0aac556221367a4495a03031     65 
120   95025d750658e2c3ceb8a124e13f11811afe4b55    66 
120   0eb7704ec46164b9f5e8b588278c9c3b7701bf25    67 
120   65f41ca9187ebb552b416ac97d42a786fb0b8da2    68 
120   86990e197cc78203af9639180496edc668f8613d    69 
120   a64935877d15b556d54b3ee2f60621e484dd41fd   7 
120   8aee8ad39bdac0b8fe0cb13cd283755a959181a2    70 
120   16bce9342bb8bca867ee0414c5c5ce7541c697f6    71 
120   c8d36420ce47f421c5e525b26eaad5940b8bd782   72 
120   eab5443cefad780ab057204ccffc4c602709f8cb       73 
120   3d6f024e1925f8b6442554cfd99548d7e89cfd08     74 
120   b7605f47dc348aa15c5e57d0ad50c065843ded67   75 
120   712a3040f2edac82f70585a88b8c1595ba2ad09b    76 
120   54a732594f317388fc189750950be58b4b7741de   77 
120   2b46b10909fb8b1bb4d454af53bd9e17d81811e5  78 
120   cb6ad8e7adb18bf4506b4e60a316773e74b96977  79 
120   edb561d4e127a0d52b17f870ad58b5bbd9cc91b8  8 
120   39867f79ba34d10e7be55d4bfc52cd1206ec04bc    80 
120   969c5f22d3f6ee1bc0a49ee0ac1080ff3d49447d      81 
120   2e01ce255e876edf3ec607920eaf6ef2ba2024b1     82 
120   fa44ff898ce7c2bb6b8f40bbae8ed1ccae95b432       83 
120   e480784e28bdbc684d8a4e7e12408362650c0c1e  84 
120   42ff9530884027e4173ecd0457f1b958ae969b3e    85 
120   824351ee034e257eed4a0aad52aeba091856d5d0  86 
120   422298b8780c9b2c5852e4f9107def2bc3ebf729     87 
120   a3455a4d0afddbb9606f37f8d682554d6d3755a9    89 
120   923ec2edb8d2220d6a63127e92d71610da3adb1c  9 
120   4c17c94727a2f9c5d0940a2c2b7850d9e18b61d9    90 
120   502aab70ea5158900ae0fe74104bb9d07494ac12   91 
120   e17fd59832c3695ac4265a51d90b1613295d9136   92 
120   788aa5b82898037c8d4dfd2e85970417c21dc927   93 
120   23e40bc7c6b410a8c07021b55897486d779ad02e  94 
120   4bdd88ea1d6592e1433622aaaac3c8ef8f914f69     95 
120   400ac010ca7fa1de3642cfc73517a415bf604895      96 
120   a82553d9e0cb92398eaa6853818035ed3b87ee0a  97 
120   fdb7edbe5ffa139bb5389a3e4ff29498905eb9f2       98 
120   43847f9d72e162a609eef175acbb332c5ba11787    99 
windows batch-file
© www.soinside.com 2019 - 2024. All rights reserved.