A Git tool that I'd like and how I probably use Git differently from most people

April 10, 2019

For a long time now, I've wished for what has generally seemed to me like a fairly straightforward and obvious Git tool. What I want is a convenient way to page through all of the different versions of a file over time, going 'forward' and 'backward' through them. Basically this would be the whole file version of 'git log -p FILE', although it couldn't have the same interface.

(I know that the history may not be linear. There are various ways to cope with this, depending on how sophisticated an interface you're presenting.)

When I first started wanting this, it felt so obvious that I couldn't believe it didn't already exist. Going through past versions of a file was something that I wanted to do all the time when I was digging through repositories, and I didn't get why no one else had created this. Now, though, I think that my unusual desire for this is one of the signs that I use Git repositories differently from most people, because I'm coming at them as a sysadmin instead of as a developer. Or, to put it another way, I'm reading code as an outsider instead of an insider.

When you're an insider to code, when you work on the code in the repository you're reading, you have enough context to readily understand diffs and so 'git log -p' and similar diff-based formats (such as 'git show' of a commit) are perfectly good for letting you understand what the code did in the past. But I almost never have that familiarity with a Git repo I'm investigating. I barely know the current version of the file, the one I can read in full in the repo; I completely lack the contextual knowledge to mentally apply a diff and read out the previous behavior of the code. To understand the previous behavior of the code, I need to read the full previous code. So I wind up wanting a convenient way to get that previous version of a file and to easily navigate through versions.

(There are a surprising number of circumstances where understanding something about the current version of a piece of code requires me to look at what it used to do.)

I rather suspect that most people using Git are developers instead of people spelunking the depths of unfamiliar codebases. Developers likely don't have much use for viewing full versions of a file over time (or at least it's not a common need), so it's probably not surprising that there doesn't seem to be a tool for this (or at least not an easily found one).

(Github has something that comes close to this, with the 'view blame prior to this change' feature in its blame view of a particular file. But this is not quite the same thing, although it is handy for my sorts of investigations.)


Comments on this page:

By radio man at 2019-04-10 02:18:34:

https://githistory.xyz/ lets you flip through commits of a github repo with animated code changes.

From 193.219.181.226 at 2019-04-10 04:05:25:

I frequently use tig for something like this. It doesn't have exactly the same feature you want, but it has two other options that should mostly do the job.

1. In log view (tig foo.c), whenever I have a diff under the cursor, I can press 'F' to get a full version of that file. Skim through it, press 'q' to go back, another commit, 'F' for full version again...

2. In blame view (tig blame foo.c), I can press ',' to jump to an earlier version of the line currently under cursor. Unfortunately it can only dig deeper and doesn't keep a history/stack (as far as I could tell) so you cannot go forwards.

From 193.219.181.226 at 2019-04-10 04:09:04:

(I just noticed that there's an unreleased commit in tig.git that lets you combine the two and access the "blame" view from whole-file view by pressing 'b'. That'll be useful...)

From 172.56.22.40 at 2019-04-10 07:54:51:

If you're willing to use emacs, git time machine does this: https://gitlab.com/pidu/git-timemachine/tree/b97f93d66cffcd69281346845d3a1e32197eda29

By ps.cks@smyrak.com at 2019-04-10 14:52:58:

vim-fugitive Gblame and its commands would be helpful, but it seems to me, that you might be looking for smth like "diff -y" that diffs file versions side by side.

By lilydjwg at 2019-04-11 02:31:29:

I use tig and vim-fugitive for this kind of tasks. tig is a great tool but unfortunately it needs some time to learn, but I don't use that much so I could remember more key bindings (and there is no syntax highlighting), so for more careful tasks I use vim-fugitive.

I use :Gblame to see which commit has changed the lines and press '~' to go further in the past if that's a trivial commit like changing indents. I can easily read the commit message, navigate to other files in that commit etc. I can also jump back and forward with normal Vim operations.

If you like GitHub, you probably prefer :Glog and then :Gdiff ^ on the resulting buffer to diff with the previous version. Unfortunately it seems not possible to combine these two operations.

By Stuart Dootson at 2019-05-23 05:40:51:

If you're willing to GUI, GitKraken has exactly this feature (Ctrl-Shift-P, enter command 'History', then select the file whose history you want, with diff view or full file view) - it's one I find useful.

Written on 10 April 2019.
« An example of a situation where Go interfaces can't substitute for generics
The tarfile module is too generous about what is considered a tar file »

Page tools: View Source, View Normal, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Wed Apr 10 01:27:06 2019
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.