Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vimdiff against a source control repo

scmdiff marks the differences between the checked in version of a file and the file that's being edited. It marks it by coloring the changed lines. Is there any way to view the changes using a vimdiff-style split instead of just coloring the changed lines?

For instance, if abc is a file under version control, then I can use the following to display the current version of abc on one side and the latest version on the other side:

tkdiff abc

I can also do:

tkdiff -r1 -r5 abc

to show the differences between versions 1 and 5. Finally, I can do:

tkdiff -r1 abc

to see the difference between the current version and version 1.

This is the sort of diff I'd like to see between two versions of a file, only using Vim. Can it be done? I'm working under Linux and I use Bitkeeper for version control.

like image 360
Nathan Fellman Avatar asked May 17 '09 18:05

Nathan Fellman


People also ask

What is Vimdiff?

Description. Vimdiff starts Vim on two (or three or four) files. Each file gets its own window. The differences between the files are highlighted. This is a nice way to inspect changes and to move changes from one version to another version of the same file.

How do I get out of Vimdiff?

Other ways to exit VimEsc + :x + Enter (Save and exit) Esc + :qa + Enter (Quit all open files) Esc + Shift ZZ (Save and exit) Esc + Shift ZQ (Exit without saving)


2 Answers

I use vimdiff with subversion the following way:

When I want to see differences in vimdiff for a specific file or a group of files I do:

svn diff [files] --diff-cmd svd

Here the --diff-cmd instructs subversion to use the command "svd" instead of its default diff behavior. svd is the following shell script:

#!/bin/bash
shift 5; /usr/bin/vimdiff -f "$@"

You did not mention your OS, the above will work for Linux and OS X for sure.

like image 111
KIV Avatar answered Oct 19 '22 01:10

KIV


I use the vcscommand plugin for interacting with a VCS.

From the description:

VIM 7 plugin useful for manipulating files controlled by CVS, SVN, SVK and git within VIM, including committing changes and performing diffs using the vimdiff system.

In particular :VCSVimDiff will split the current window and show a "vimdiff" against the latest version in the repo. You can also specify one revision number to compare the current buffer to (i.e. :VCSVimDiff -2), or two revision numbers to diff to each other. Here is the relevant section from the docs:

:VCSVimDiff

Uses vimdiff to display differences between versions of the current file.

If no revision is specified, the most recent version of the file on the current branch is used. With one argument, that argument is used as the revision as above. With two arguments, the differences between the two revisions is displayed using vimdiff.

With either zero or one argument, the original buffer is used to perform the vimdiff. When the scratch buffer is closed, the original buffer will be returned to normal mode.

Once vimdiff mode is started using the above methods, additional vimdiff buffers may be added by passing a single version argument to the command. There may be up to 4 vimdiff buffers total.

Using the 2-argument form of the command resets the vimdiff to only those 2 versions. Additionally, invoking the command on a different file will close the previous vimdiff buffers.

like image 28
user55400 Avatar answered Oct 19 '22 02:10

user55400