终端Git日志浏览器

viewlog的Python项目详细描述


viewlog是一个命令行工具,用于浏览文件的历史版本 使用git存储,并在 less(或 你的选择)。

$ viewlog ~/git/rmed/sh/rmed
 Pick your git commit id (choose 'exit' or ctrl-c to quit)
 File: /Users/rouble/git/rmed/sh/rmed

 => 20000e5e59270e99bc134b9acade8c722cc410de - 4 days ago, Rajnikant blessed the code thusly: rewrote from scratch.
    8c0d5009b69afeca06333b8efd3a4690b92f64f5 - 4 days ago, Chuck Norris blessed the code thusly: obliterated all bugs.
    f8b2265944f10a4de3de3113bdb654b22c4fb65f - 4 days ago, Bernie Sanders blessed the code thusly: raised taxes.
    ae45df5ea466778a62da394370854ed49833696a - 4 days ago, Jackie Chan blessed the code thusly: karate chopped bugs.
    eafce9c6d5e742c59da35daeaffdd681a9ba8d14 - 4 days ago, The Hulk blessed the code thusly: smashed bugs.
    0f2d343409a843b14861d385fd000440eb1360ca - 4 days ago, rouble blessed the code thusly: did I mention, more features?
    5e61aa5dce263bdfd6adf0a3bca34d9ab66fbf08 - 4 days ago, rouble blessed the code thusly: more features.
    e1a61f877c085dd79b863c0664007fc2c9880bda - 5 days ago, rouble blessed the code thusly: more features.
    8b10be72399c66a51462e7c8cd801b726ea6bab9 - 5 days ago, rouble blessed the code thusly: more features.
    f1711513272d8e1dda0db73f1f491c7a575c2f91 - 6 days ago, r0uble blessed the code thusly: more features.
    next page
    exit

安装

如果您有PIP,请安装一行:

$ pip install viewlog

$ git clone https://github.com/roubles/viewlog
$ cd viewlog
$ python setup.py install

注意,viewlog依赖于pypi包pick。如果没有 自动安装,您需要:

$ pip install pick

必需的动画gif:alt tag

帽子尖

给wong2的帽子小费 用于游标选择器实现的库。

动机

我知道外面有很多GitGui。但我喜欢终端。 也许我是老派。我用这个bash函数 时间:

vimgitshow() { git show "$1" | vim - "+set filetype=${1##*.}"; }

…但后来我决定把一些代码放在一起浏览历史 并使用任何编辑器打开文件。

用法

usage: viewlog [-h] [-e EDITOR] [-s SKIP] [-l LIMIT] [-f LOGFORMAT]
               [-b BRANCH] [-n] [-a AFTER] [-u BEFORE] [-g GREP]
               [-o LOGOPTIONS] [-k]
               filename

terminal git log browser

positional arguments:
  filename              Path to filename

optional arguments:
  -h, --help            show this help message and exit
  -e EDITOR, --editor EDITOR
                        Editor to use
  -s SKIP, --skip SKIP  Starting commit offset
  -l LIMIT, --limit LIMIT
                        Total commits to show
  -f LOGFORMAT, --logformat LOGFORMAT
                        Pretty format for git commit
  -b BRANCH, --branch BRANCH
                        Branch to use
  -n, --nomerges        Do not include commits from merged branches (Default:
                        false)
  -a AFTER, --after AFTER
                        Commits after/since date
  -u BEFORE, --before BEFORE
                        Commits before/until date
  -g GREP, --grep GREP  Limit the commits output to ones with log message that
                        matches the specified pattern (regular expression)
  -o LOGOPTIONS, --logoptions LOGOPTIONS
                        Extra options to pass directly to git log. (Escape the
                        -- using \-\-)
  -k, --keeptemp        Keep any created temp files (Default: false)

自定义编辑器

默认编辑器是less(记住,less就是more),但是可以是 改变。

$ viewlog <filename> --editor [vi|vim|mvim|gvim|less|more|emacs|<your editor here>]

从版本1.1.4开始,支持操作系统emacs。

也可以打开二进制文件。例如在Mac上打开 动画gif,我知道:

$ viewlog viewlog.gif --editor "open -a Safari"

自定义日志行

你可以把记录线改成任何你想要的 参数仍然是提交ID(%h或%h):

$ viewlog README.md --logformat "%h - %ad, %an: %s"
 => b2f88c8 - Sun Jan 24 15:21:57 2016 -0500, roubles: emacs ftw!
    d443a7c - Sun Jan 24 15:19:59 2016 -0500, roubles: vim ftw!
    cb47e52 - Sun Jan 24 15:17:26 2016 -0500, roubles: Will it blend?
    750b153 - Sun Jan 24 15:16:06 2016 -0500, roubles: All your base are belong to us.
    1e283cf - Sun Jan 24 00:58:41 2016 -0500, roubles: Update README.md
    8bba27e - Sun Jan 24 00:57:52 2016 -0500, roubles: Update README.md
    5be85d5 - Sun Jan 24 00:55:28 2016 -0500, roubles: Update README.md
    cbf5d8e - Sun Jan 24 00:48:13 2016 -0500, roubles: Update README.md
    edaceb1 - Sun Jan 24 00:45:01 2016 -0500, roubles: Update README.md
    918166c - Sun Jan 24 00:34:54 2016 -0500, rouble: initial commit
    next page
    exit

搜索

可以对日志中包含特定模式的提交进行grep 消息

Match any commits with "[M|m]ore" in the log message
$ viewlog rmed --grep "[M|m]ore"
 Pick your git commit id (choose 'exit' or ctrl-c to quit)
 File: /Users/rouble/git/rmed/sh/rmed

 => e1a61f877c085dd79b863c0664007fc2c9880bda - 5 days ago, rouble blessed the code thusly: more features
    8b10be72399c66a51462e7c8cd801b726ea6bab9 - 5 days ago, rouble blessed the code thusly: More features.
    f1711513272d8e1dda0db73f1f491c7a575c2f91 - 6 days ago, rouble blessed the code thusly: More features
    exit

高级搜索

通过使用 –登录功能

Only match commits with the leter "[M|m]" AND the letter "n" in the log message
$ viewlog rmed --grep "[M|m]" --logoptions="\-\-grep=n \-\-all-match"
 Pick your git commit id (choose 'exit' or ctrl-c to quit)
 File: /Users/rouble/git/rmed/sh/rmed

 => 680930c9aa5f176bfa9961d0d142e41f67a74dad - 6 days ago, rouble blessed the code thusly: Add footer and some documentation.
    exit

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java ActiveMQ 5.9.0、Glassfish 3.1.2和MDB用于长时间的消息处理   从main调用的对象数组的Java字符串表示形式   java如何在iText 7中为泰国字母上方的双标记设置GPO   编译如果Java6工件是用Java6、7或8编译的,这有关系吗?   image Java KeyListener未检测到键盘输入   java找不到符号(构造函数)   java如何使Kafka使用者从特定主题分区读取Spring Boot   Java readLine()返回null   从CSV文件计算值时出现java系统错误   java如何避免处理程序。被调用后延迟(可运行运行)?   Java Do和While验证   java如何访问父类型的ArrayList中的子方法?   java如何使用Deepfirstsearch算法获得最高级别的搜索   xml使用SAX解析器Java正确构建字符串   Android片段中的java Toast显示空指针expn   如何在java中将多个文件合并到另一个新文件中?   java在运行时在JVisualVM中更改应用程序的标题   javajavax。命名。NoInitialContextException:需要在环境或sys中指定类名