git-log it’s easy to quickly skim history in the form of patches, but it’s a bit harder to have a quick look at different revisions of a file or to see the difference between two arbitrary versions.
fugitive.vim provides tools to do just that.
View previous file revisions
Glog is a wrapper around
git log <current file>. Upon execution it shows all commits that affect the opened file, then it loads the latest revision into the buffer. It also populates the quickfix list with the latest revisions of the file.
There are multiple options to investigate the file history.
You can use
copen right after
Glog to open the quickfix window where you can select any version to load it into the buffer.
As an alternative, you can use
cprev to cycle through the revisions of the file.
The revisions are presented in a read-only buffer. You can return to the working copy of the file with the
- If the file has a long history that you are not interested in you can limit the results by supplying additional parameters to
Glog. For example,
Glog -10returns the last 10 entries only. For more options, check out
- The vim-airline plays nicely with
fugitive.vim. It shows the commit hash when you are viewing older versions and reminds you that you are viewing a read-only buffer.
- For more examples check out this Vimcast.
We write articles like this regularly. Join our mailing list and let's keep in touch.
Difference between revisions
After you’ve selected a revision, you can easily compare it to any other version with
Gdiff, with no arguments: compare with the working copy.
Gdiff HEAD: compare to the latest revision.
Gdiff <rev>: compare to an arbitrary revision. As usual, it’s enough to provide the first few characters of the SHA-1 hash.
Gvdiff instead of
Gdiff to open the diff vertically aligned.
fugitive.vim nicely augments the command-line git workflow. Its commands are oriented around the currently edited file, which makes it handy for many tasks, for example checking file history or revision information.