git - 在 python 子进程中使用 git shortlog 获取每个文件的贡献者

标签 git python-3.x

当我尝试获取以下命令的输出时遇到问题: git shortlog -s -- [文件路径] 使用 python 3.6 子进程模块。

这里是代码:

import subprocess

x = subprocess.Popen(['git shortlog -s -- ' + file_path], cwd=path, 
shell=True, stdin=subprocess.PIPE, 
stdout=subprocess.PIPE).communicate()[0]
print(x)

执行结果为空。 我做错了什么?

最佳答案

你需要调用git shortlog HEAD

subprocess.Popen(['git shortlog HEAD -s -- ' + file_path],
                  cwd=path,  shell=True, stdin=subprocess.PIPE, 
                  stdout=subprocess.PIPE).communicate()[0]

要了解原因,请参阅 https://stackoverflow.com/a/43042420/4381942

关于git - 在 python 子进程中使用 git shortlog 获取每个文件的贡献者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46676481/

相关文章:

git - 交换主分支和特性分支

git merge diffs应用流程与rebase对比

Python - Selenium - 打印网页

python - 装饰递归函数

python - Windows 上 Python 3 的基于 Web 的安装程序和可执行安装程序之间的区别

python - 选择二维数组第二维的特定元素

git - 每工作树本地排除

c++ - 使用 iOS 或 c/c++ 访问 SVN 或远程 Git 存储库等

git push 使用 maven 发布插件失败

python - EOFError Python 2.7 到 3 的迁移