我正在尝试编写一个“实时 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/