如何在python中执行'lsremote heads origin master'?

2024-09-27 21:26:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我的git repo中有一些基本的python脚本。 首先,我在repo中测试一些git命令:

$ git ls-remote --heads origin master
a5dd03655381fcxxxx4e759ceba7aeb6456 refs/heads/master

现在我想在Python中执行相同的命令:

^{pr2}$

输出为:

git: 'ls-remote --heads origin master' is not a git command. See 'git --help'.
OK

我错过了什么? 当我在python脚本中执行ls-remote时,它可以工作:

a5dd03655381fcxxxx4e759ceba7aeb6456 HEAD
a5dd03655381fcxxxx4e759ceba7aeb6456 refs/heads/master

(我知道if语句是“错误的/无用的”)。在


Tags: git命令master脚本remoteisnotrepo
1条回答
网友
1楼 · 发布于 2024-09-27 21:26:04

您需要将每个参数放在列表中的单独项中。在

import subprocess

if subprocess.call(["git", "ls-remote", " heads", "origin", "master"]):
    print("OK")
else:
    print("Not OK")

相关问题 更多 >

    热门问题