![](/img/trans.png)
[英]How to connect to a GIT remote repository with ssh and IPV6 on Windows
[英]How to extract latest commit hash for a remote git repository in Windows?
我正在嘗試使用此命令讀取 git 遠程存儲庫的最新提交
git ls-remote https://repo.myrepository.com/scm/swc/project.git refs/heads/qa
它工作正常並返回給我這樣的東西
5261626431661281d788382a1ed6ab1440fd93a8 refs/heads/qa
但是我無法在網上找到任何方法來僅從命令行中返回的字符串中提取提交哈希
我認為在網上找到這些信息會很容易,但我到處都能找到的唯一答案是這個
git ls-remote https://repo.myrepository.com/scm/swc/project.git refs/heads/qa | \ cut -f 1
但這在 Windows 命令行中不起作用,它說cut
不是可識別的命令。
任何人都可以幫助它的Windows命令行版本嗎?
for /f
是您如何使用分隔符“剪切”令牌。
在以下示例中, delims
是Space 。
# inside of a batch file
# get first token, delimited by <space>
for /f "tokens=1,* delims= " %%a in (
'git ls-remote https://repo.myrepository.com/scm/swc/project.git refs/heads/qa'
) do echo %%a
# command line
# get second token, delimited by <space>
for /f "tokens=2,* delims= " %a in ('echo one two') do echo %a
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.