如何从python脚本中调用git clean -df命令

时间:2018-01-08 09:50:36

标签: python git

我是python的新手并尝试在python脚本中使用git命令。 要求是我需要在我的python脚本中调用一些git命令,如git clean和git reset命令。我需要使用子进程,因为我不能使用任何外部库,如GitPython。

任何帮助将不胜感激

感谢。

1 个答案:

答案 0 :(得分:0)

你可以像下面那样使用它

import shlex
import subprocess 

command= "git clean -df" # you can paste any command here
comm=shlex.split(command) # This will convert the command into list format

proc=Popen(comm) # This will execute your command

有关更多详细信息,请参阅此处

https://docs.python.org/2/library/subprocess.html

相关问题