git blametool
我围绕git blame 编写了一个简单的包装器,效果很好。我称之为git blametool。得到它in my eRCaGuy_dotfiles repo here。调用git blametool 在您选择的“blametool”中打开git blame 输出——它可以是any 文本编辑器。文本编辑器的示例包括:vim、emacs、gedit、nano、Sublime Text 3(subl,默认值,也是我的首选)等。
安装
有关最新的安装说明,请参阅git-blametool.sh 本身顶部内的 cmets。有很多方法可以做到这一点,但这里有一些可能的安装说明:
mkdir ~/dev # make development dir
cd ~/dev
git clone https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles.git
cd eRCaGuy_dotfiles/useful_scripts
# make symbolic link to "git-blametool.sh" inside ~/bin
mkdir -p ~/bin
ln -si "${PWD}/git-blametool.sh" ~/bin/git-blametool
关闭并重新打开您的终端。假设~/bin 是您的PATH 的一部分(如果您创建~/bin 目录然后注销并重新登录,它默认在Ubuntu 上),现在您可以访问git-blametool,它可以简单地运行作为git blametool。
运行 git blametool -h 以获得完整的帮助菜单。
设置你的 blametool 编辑器(详见git blametool -h):
# set your blametool editor as Sublime Text 3 (its command-line executable is 'subl'):
git config --global blametool.editor subl
# Other popular choices:
git config --global blametool.editor vim
git config --global blametool.editor emacs
git config --global blametool.editor nano
git config --global blametool.editor gedit
git config --global blametool.editor leafpad
如果没有,请获取 Sublime Text 3:https://www.sublimetext.com/3。
安装 Git 插件,以便获得“git blame”语法高亮:Ctrl + Shift + P --> "Package Control: Install Package" --> 输入 "Git" 并选择那个包。
用法
现在运行git blametool!它是git blame 的包装器,因此它接受git blame 接受的任何 选项!
示例用法:
git blametool -h # help menu
git blametool somefile.c
git blametool somebranch somefile.c
演示
在我上面克隆的eRCaGuy_dotfiles repo 中,运行:
git blametool useful_scripts/git-diffn.sh
您会看到如下内容:
让我们深入挖掘。在第 8 行,我看到了提交哈希 68e96491,所以我在 Sublime Text 中双击它并复制它。现在我可以在终端中运行它了:
git blametool 68e96491 useful_scripts/git-diffn.sh
现在我看到了:
注意现在在 Sublime Text 3 中打开了 2 个选项卡,每个选项卡都显示来自 git blame 的提交哈希作为文件名的一部分。我想更深入地挖掘,所以我从第一行复制哈希并运行:
git blametool c294f965 useful_scripts/git-diffn.sh
它将git blame 打开到 Sublime Text 3 的第三个选项卡中。现在我看到了:
我可以轻松地点击 3 个标签。凉爽的。现在想象一下我找到了我正在寻找的东西,所以为了查看并排比较,我运行它来查看meld 中的提交哈希c294f965 和68e96491 之间的比较:
git difftool 68e96491 68e96491 useful_scripts/git-diffn.sh
这就是我所看到的:
如果您没有设置meld,请按照我在此处的回答中的说明操作:Git mergetool with Meld on Windows。
git blametool 的替代方案
这里有几个选择:
-
GitHub
- 只需导航到 GitHub 上的存储库中的文件,然后单击“Blame”链接as shown here:。
- 您现在将在 GitHub 中看到一个漂亮的
git blame 视图,如下所示。请注意,您可以单击这些时髦的窗口图标以进一步返回 git blame 历史记录:。例如,单击上图中的那个就像运行git blametool 68e96491 useful_scripts/git-diffn.sh,因为该行的git blametool 输出显示68e96491 是它的提交哈希。
-
“Git Blame”Sublime Text 3 包。我更喜欢我的
git blametool,但这也是一个选项:
- https://packagecontrol.io/packages/Git%20blame
- https://github.com/frou/st3-gitblame
另见
- 非常有用!查看单个文件的编辑历史!
git log -p somefile.c
灵感来源:Git blame -- prior commits?
- [我的回答]Git mergetool with Meld on Windows
关键词:git blametool;在您选择的编辑器中打开git blame