Step through a file's history in git; similar to p4v timelapse
GitGit Problem Overview
I'm seeking a tool to help when probing a file's history. Specifically, I want to view the entire contents of the file, but be able to step backward and forward in time. Extra joy for decorations indicating the diff from previous rev or some other specified rev.
Currently I use git blame
, and can see what changes impacted each current line. Then I have to relaunch a viewer for that file with some particular commit. It's labor intensive, and if a tool already automates this I'd love to use it!
Perforce's timelapse view is the best tool to date I've seen for this task.
Git Solutions
Solution 1 - Git
gitk -- filename
should do what you want, if you kick up the lines of context in the middle, and scroll up and down through the revisions.
Solution 2 - Git
Tig, a text mode interface for git, offers a blame view that offers some of this functionality:
- Step backwards in time to the commit of a given line (b key).
- Step backwards to the parent commit of a given line (, key).
- Returning forwards in time to a view you were at previously (< key).
It does not preserve the viewing location when stepping to a parent commit (it seems to when using the line's commit).
Solution 3 - Git
Here is a Git Time-Lapse View tool that I have written in Java:
Solution 4 - Git
git gui blame is an option, although it's not as good.
Example for gc_storage from Ansible:
git gui blame --line=155 library/cloud/gc_storage
Right click a line and select Blame Parent Commit to move back in time, returning to more recent changes with the view history arrow in the top left.
Solution 5 - Git
If you are using vim, the git-time-lapse plugin could also help you.
It allows you to navigate through history for a file, presenting each commit in vimdiff form, with the commit message in a separate vsplit below.
Solution 6 - Git
Try https://github.com/pomber/git-history which shows full file with beautiful slide-in animations as you move on horizotal timeline:
You don't even need to install it, just change the domain on any Github file url!
Weak points, as of this writing:
- No indication where changes happened outside viewport, you have to know to scroll to region that's going to change.
- Small changes within a line hard to see, as whole line is replaced. No way to see same line before/after stacked vertically as in "unified diff". https://github.com/pomber/git-history/issues/26, https://github.com/pomber/git-history/issues/22 However, you can click commit to go to full github diff.
Solution 7 - Git
I have a Perl script (too big and too general to post as an answer to this question) that grabs a copy of each revision of a specified file in git. (It also works with RCS and CVS).
EDIT : I've finally gotten around to releasing it on Github.
The core of it is this (pseudo-code):
- Run
git log --date=raw -- filename
- Search the output for
commit
andDate:
lines. - For each commit-id:
- Run
git show commit-id ./filename > target-filename
- Run
The target-filename is constructed from some combination of the commit-id, the timestamp, and/or a sequential index.
The result might be, for example, a bunch of files like:
foo__001.txt
foo__002.txt
foo__003.txt
where each is a version of foo.txt
from the git repository. I can then view each file and/or diff consecutive versions of it.
This doesn't give you everything you're asking for, but it should be a good start.
Solution 8 - Git
You could also use something like github if you wanted to - its history view for a particular file shows you a synopsis of when each file was edited and by whom, and gives you handy links to view the diff of that file for that commit, the current version of the file at that commit, etc.
Solution 9 - Git
If you are using Visual Studio, CodeLineage is nice.
https://visualstudiogallery.msdn.microsoft.com/bb3d22aa-29bf-41e1-acc9-92482bee4646
I like that the Git Time-Lapse by Jonathan Aquino shows you the commit comment, but CodeLineage is nice because it integrates in Visual Studio and you can select the two revisions you are comparing, instead of just comparing each revision with its previous revision.