为什么我喜欢 Tig 来可视化我的 Git 工作流

Tig 是一个优秀的工具,用于审查您的 Git 仓库,它鼓励您探索日志,而无需构建冗长且有时复杂的查询。
4 位读者喜欢这篇文章。

opensource.com

如果您发现浏览 Git 仓库的过程令人沮丧且复杂,那么我为您准备了一个工具。认识一下 Tig。

Tig 是一个基于 ncurses 的文本模式 Git 界面,允许您浏览 Git 仓库中的更改。它还可以充当各种 Git 命令输出的分页器。我使用这个工具来很好地了解哪个提交中更改了什么,由谁更改,以及最新合并的提交等等。从这个简短的教程开始,亲自尝试一下。

安装 Tig

在 Linux 上,您可以使用软件包管理器安装 Tig。例如,在 Fedora 和 Mageia 上:

$ sudo dnf install tig

在 Debian、Linux Mint、Elementary、Pop_OS 和其他基于 Debian 的发行版上:

$ sud apt install tig

在 macOS 上,使用 MacPortsHomebrew。Tig 的完整安装指南可以在 Tig 手册中找到。

使用 Tig

Tig 提供了常见 Git 输出的交互式视图。例如,使用 Git,您可以使用命令 git show-ref 查看所有引用。

$ git show-ref
98b108... refs/heads/master
6dae95... refs/remotes/origin/1010-internal-share-partition-format-reflexion
84e1f8... refs/remotes/origin/1015-add-libretro-openlara
e62c7c... refs/remotes/origin/1016-add-support-for-retroarch-project-cd
1c29a8... refs/remotes/origin/1066-add-libretro-mess
ffd3f53... refs/remotes/origin/1155-automatically-generate-assets-for-external-installers
ab4d14... refs/remotes/origin/1160-release-on-bare-metal-servers
28baa9... refs/remotes/origin/1180-ipega-pg-9118
8dff1d... refs/remotes/origin/1181-add-libretro-dosbox-core-s
81a7fe... refs/remotes/origin/1189-allow-manual-build-on-master
[...]

使用 Tig,您可以在一个可滚动的列表中获得该信息以及更多信息,还可以使用键盘快捷键打开其他视图,其中包含有关每个引用的详细信息。

Screenshot of a terminal using Tig. On the left there is a scrollable list of outputs, on the right the details of the selected output (add become an ambassador page) is shown, such as author, date, commit date, sign off, etc.

(Sumantro Mukherjee, CC BY-SA 4.0)

分页模式

当输入被提供给 stdin(标准输入)时,Tig 进入分页模式。当指定 show 子命令并给出 --stdin 选项时,stdin 被假定为提交 ID 的列表,这些提交 ID 被转发到 git-show

$ git rev-list --author=sumantrom HEAD | tig show –stdin

日志和差异视图

当您处于 Tig 的日志视图中时,您可以按键盘上的 d 键来显示差异。这将显示提交中更改的文件以及删除和添加的行。

交互式 Git 数据

Tig 是 Git 的一个极好的补充。它使审查您的 Git 仓库变得容易,它鼓励您探索日志,而无需构建冗长且有时复杂的查询。

立即将 Tig 添加到您的 Git 工具箱中!

接下来阅读什么
标签
User profile image.
嘿,开源爱好者们!我是来自印度的 Sumantro(来自东部 - 英国时代的前首都,又名加尔各答)。我喜欢分享知识,撰写关于技术和经验的文章(主要是我每天尝试的)。

评论已关闭。

知识共享许可协议本作品采用知识共享署名-相同方式共享 4.0 国际许可协议授权。
© . All rights reserved.