git blametool
I wrote a simple wrapper around git blame
which works pretty well. I call it git blametool
. Get it in my eRCaGuy_dotfiles repo here. Calling git blametool
opens up the git blame
output in your "blametool" of choice--which can be any text editor. Examples of text editors include: vim
, emacs
, gedit
, nano
, Sublime Text 3 (subl
, the default, and my preferred choice), etc.
Installation
For the latest installation instructions, see the comments inside the top of git-blametool.sh itself. There are many ways to do this, but here are some possible installation instructions:
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
Close and re-open your terminal. Assuming ~/bin
is part of your PATH
(it is on Ubuntu by default if you create the ~/bin
dir and then log out and log back in), now you have access to git-blametool
, which can be run simply as git blametool
.
Run git blametool -h
for the full help menu.
Set your blametool editor (see git blametool -h
for details):
# set your blametool editor as Sublime Text 3 (its command-line executable is 'subl'):
git config --global blametool.editor subl
# see what your current setting is
git config --global blametool.editor
# Other popular choices to set as your blametool editor:
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
git config --global blametool.editor code # VSCode
Get Sublime Text 3 if you don't have it: https://www.sublimetext.com/3.
Install the Git plugin so you get "git blame" syntax highlighting: Ctrl + Shift + P --> "Package Control: Install Package" --> type in "Git" and choose that package.
Usage
Now run git blametool
! It's a wrapper around git blame
so it accepts any options that git blame
accepts!
Example usage:
git blametool -h # help menu
git blametool somefile.c
git blametool somebranch somefile.c
Demo
Inside my eRCaGuy_dotfiles repo that you just cloned above, run:
git blametool useful_scripts/git-diffn.sh
You'll see something like this:
Let's drill down deeper. On line 8 I see commit hash 68e96491
, so I double-click on it in Sublime Text and copy it. Now I can run this in my terminal:
git blametool 68e96491 useful_scripts/git-diffn.sh
And now I see:
Notice there are 2 tabs open in Sublime Text 3 now, each showing the commit hash from the git blame
as part of the file name. I want to dig deeper, so I copy the hash from the first line and run:
git blametool c294f965 useful_scripts/git-diffn.sh
It opened up this git blame
into a 3rd tab in Sublime Text 3. Now I see this:
I can easily click around the 3 tabs. Cool. Now imagine I found what I was looking for, so to see a side-by-side comparison I run this to look at the comparison between commit hash c294f965
and 68e96491
in meld
:
git difftool 68e96491 68e96491 useful_scripts/git-diffn.sh
And here's what I see:
If you don't have meld
set up, follow my instructions in my answer here: Git mergetool with Meld on Windows.
Alternatives to git blametool
Here are a few alternatives:
- GitHub
- Just navigate to a file in a repo on GitHub and click on the "Blame" link as shown here: .
- You'll now see a nice
git blame
view in GitHub like this. Notice you can click on these funky window icon things to go back farther into the git blame
history: . Clicking on the one in the picture above, for instance, would be like running git blametool 68e96491 useful_scripts/git-diffn.sh
, since the git blametool
output for that line shows 68e96491
is its commit hash.
- "Git Blame" Sublime Text 3 package. I like my
git blametool
better, but this is an option too:
- https://packagecontrol.io/packages/Git%20blame
- https://github.com/frou/st3-gitblame
See also
- VERY USEFUL! View the edit history of a single file!
git log -p somefile.c
Inspired by: How can I view prior commits with git blame?
- [my answer] Git mergetool with Meld on Windows
Keywords: git blametool
; open git blame
in the editor of your choice