git - 从 bash 脚本退出 git log

标签 git bash mingw pager

我正在尝试编写一个“实时 git 日志”bash 脚本。 到目前为止,这是代码:

#!/bin/sh
while true;
do
    clear
    git log --graph -10 --all --color --date=short --pretty=format:"%Cred%x09%h %Creset%ad%Cblue%d %Creset %s %C(bold)(%an)%Creset"
    sleep 3
done

我的问题是 git log 使用寻呼机,你必须按 q 退出,否则它将永远停在那里。有没有办法在 bash 中编写退出命令?我试着回应 q,但没有成功。 (我在这里看到另一篇帖子建议 echo "q">/dev/console -- 但我的环境中没有开发控制台)

系统:win7 box - 用mingw模拟bash (1.7.6.msysget.0)

更新

这是完成的脚本

#!/bin/sh
while true;
do
    clear
    git log \
    --graph \
    --all \
    --color \
    --date=short \
    -40 \
    --pretty=format:"%C(yellow)%h%x20%C(white)%cd%C(green)%d%C(reset)%x20%s%x20%C(bold)(%an)%Creset" |
    cat -
    sleep 15
done

-40 是个人品味。将其更改为适合您和您的终端屏幕尺寸的数字。

最佳答案

添加 --no-pager 是要走的路。:

git --no-pager log

所以完整的命令是

git --no-pager log --graph -10 --all --color --date=short --pretty=format:"%Cred%x09%h %Creset%ad%Cblue%d %Creset %s %C(bold)(%an)%Creset"

关于git - 从 bash 脚本退出 git log,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12677002/

相关文章:

gcc - 在 Windows 上将 c++ dll 与 Haskell-Platform 链接,输出 'undefined reference'

windows - Windows 上的 PCSC-Lite 代码

git - 为什么 git diff 显示修改后的相同文件?

git - Mercurial - "future auditing"是什么?

arrays - 如何将 "empty line"模式的文件拆分为变量数组? (仅使用 native bash)

arrays - bash- 求行中数字的平均值

git - 使用 git merge 不相交的分支

git - 添加和克隆远程存储库有什么区别?

bash - 将参数传递给 bash 函数时 "$@"和 "$*"之间的区别

MinGW(未找到 x86_64-w64-mingw32-gcc)