Simon219
Simon219

Reputation: 51

Vimdiff files between git branches

I have been working on my own branch for a while. However, I could not reproduce the results produced by the master branch. So I am now checking the difference between the scripts to debug. Is there any way to compare the scripts between branches like vimdiff?

Upvotes: 2

Views: 4577

Answers (2)

J0llyver
J0llyver

Reputation: 37

If you have vimdiff configured as your git difftool and you want to compare branch foo with branch bar switch to branch foo and run:

git difftool bar

To set vimdiff as difftool run following command:

git config --global diff.tool vimdiff

Upvotes: 4

romainl
romainl

Reputation: 196566

I wrote this gist precisely so that I can compare the current buffer with an arbitrary spec. I typically use it like this: :Diff origin/branch-name.

function! Diff(spec)
    vertical new
    setlocal bufhidden=wipe buftype=nofile nobuflisted noswapfile
    let cmd = "++edit #"
    if len(a:spec)
        let cmd = "!git -C " . shellescape(fnamemodify(finddir('.git', '.;'), ':p:h:h')) . " show " . a:spec . ":#"
    endif
    execute "read " . cmd
    silent 0d_
    diffthis
    wincmd p
    diffthis
endfunction
command! -nargs=? Diff call Diff(<q-args>)

example

Upvotes: 8

Related Questions