python sh git.diff ('HEAD' ) block

标签 python git

以下脚本 block :

from sh import git 
git.diff('HEAD')

如果我中断我得到以下回溯:

^CTraceback (most recent call last):
  File "main.py", line 2, in <module>
    git.diff('HEAD')
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 726, in __call__
    return RunningCommand(cmd, call_args, stdin, stdout, stderr)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 291, in __init__
    self.wait()
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 295, in wait
    self._handle_exit_code(self.process.wait())
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 1096, in wait
    pid, exit_code = os.wait

但是,git.branch() 运行良好。那么我需要做什么才能使用 python sh 获得 git diff 输出?

Python v.2.7 Git v.1.7.9.5

最佳答案

如果你的 git diff 输出超过一个屏幕(记不太清楚了,大约 48 行),git diff 会等待你按 q 退出或使用其他键继续 : 提示。

正如@phobic 在评论中指出的那样,可以使用 --no-pager git 选项来防止输出分页。

对于命令等待用户输入的一般情况,可以实现交互处理,类似于tutorial中的一个。 .

关于python sh git.diff ('HEAD' ) block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20075331/

相关文章:

python - 用两种颜色分离seaborn barplot

python - "AttributeError: ' 模块 ' object has no attribute"数组

Python 3.7 属性错误 : 'list' object has no attribute 'split'

windows - 无法在 Windows Server 2008 中加载 Rcpp 包

windows - 我可以通过 cmd.exe 在 Windows 上为 git 设置自动完成吗?

Python 3 单元测试,创建单例类函数的模拟

git - 如何在 GitHub 中创建嵌套存储库?

git - 如何使用SRC_URI获取浅拷贝?

git - 不小心 merge 到我的错误分支。有没有办法删除这些不需要的文件?

python - 如何从 PyOpenGL 中的单个数组中提取 glVertexPointer() 和 glColorPointer() 的数据?