如何使git-log向上滚动而不是向下滚动 [英] How to make git-log scroll up instead of down

查看:309
本文介绍了如何使git-log向上滚动而不是向下滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我在终端仿真器中查看git log --all --graph --oneline --decorate输出时,都会在终端屏幕的顶部查看第一次提交.当我用q退出git log输出视图时,中的几行不再可见,因为在屏幕底部添加了一些新行,用于下一个命令.

Whenever I view a git log --all --graph --oneline --decorate output in my terminal emulator, the first commit is viewed at the top of the terminal screen. When I quit the git log output view with q, a few lines from the are not visible any more, as there are some new lines appended to the bottom of the screen, for the next command.

通常,那些最上面的几行是最有趣的,因为它们类似于最新的git历史记录,因此我希望当我键入下一个git命令时它们仍然可见.

Usually though, those top lines are the most interesting, as they resemble the most recent git history, so I want them to be still visible when I type the next git command.

如何使git log输出从屏幕底部开始显示,即使得第一次提交在底部显示?您必须向上滚动才能查看较早的提交.

How can I make the git log output appear starting at the bottom of the screen, i.e. such that the first commit is viewed at the bottom? You would have to scroll up to view older commits.

注意:出于两个原因,不能选择--reverse标志.

NOTE: The --reverse flag is not an option for two reasons.

  1. 每次您都必须一直滚动到底部才能查看第一个 提交.那应该没有必要.我想从底部开始.
  2. 它不与--graph标志:fatal: cannot combine --reverse with --graph组合.
  1. Each time you have to scroll all the way to the bottom to view the first commits. That should not be necessary. I want to start at the bottom.
  2. It doesn't combine with the --graph flag: fatal: cannot combine --reverse with --graph.

推荐答案

这是一个似乎可以解决大多数极端情况的答案.没有经过全面测试.

This is an answer that seems to catch most edge cases. Not tested thoroughly.

[alias]
    rlog = !"git --no-pager log --all --graph --decorate --oneline --color=always | tac | awk -f ~/switchslashes.awk | less -X +G -r"

文件~/switchslashes.awk所在的

{
    match($0,/([[:space:][:cntrl:]|*\/\\]+)(.*)/,a) # find the segment of the graph
    tgt = substr($0,RSTART,RLENGTH)     # save that segment in a variable tgt
    gsub(/\//,RS,tgt)                   # change all /s to newlines in tgt
    gsub(/\\/,"/",tgt)                  # change all \s to /s in tgt
    gsub(RS,"\\",tgt)                   # change all newlines to \s in tgt
    gsub(/_/,"¯",tgt)                   # change all _ to ¯ in tgt
    print tgt substr($0,RSTART+RLENGTH) # print tgt plus rest of the line
}

which is a modified version of this script. It replaces underscores with overlines and swaps slashes with backslashes and vice versa. This fixes the graph after the text has been reversed by tac.

免责声明

我从来没有开始使用它,因为它在大型存储库中运行缓慢.它需要加载所有内容,然后应用替换,这花了我很多时间.

I never started using this, since it is slow with larger repositories. It needs to load everything and then apply the substitutions, which take too much time for my taste.

这篇关于如何使git-log向上滚动而不是向下滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆