在批处理脚本中 Git 命令后关闭 cmd window

Close cmd window after Git command in batch script

我写了一个简短的批处理脚本 (Windows 7) 来捆绑一个 Git 存储库并在网络驱动器上保存一个副本:

@ECHO OFF
cd /D E:/mypath/myrepo.git
start "Window title" "C:\pathto\Git\git-cmd.exe" git bundle create X:/outpath/name.bundle --branches --tags

这按预期工作,但是,我希望 window 在完成后关闭。我试过 exit 但 window 只是 returns 到 cd 指定的目录并保持打开状态。

如何关闭 window? (我在其他帖子中看到了很多推测性的答案,我想问的是在这种情况下如何 really/actually 关闭 window)

试试 :

start "Window title" "C:\pathto\Git\git-cmd.exe" git bundle create X:/outpath/name.bundle --branches --tags ^&exit 

要退出控制台当然需要exit命令。要在一行上执行两个命令,您通常使用 ampersand . But in this case you want the exit as part of START command ,but not be executed after start so you escape& with caret.