How can I diff two branches with fugitive?
Asked Answered
E

2

11

In fugitive I can get the git status in a new window by :Gstatus and in that window to D on a file to get the diff in a new split.

It is also possible to get all versions of a file using :Glog and I can load all previous commits with :Glog --.

What I would like to do is to get a Gstatus window for the diff of two branches. For example my topic and development branch so I can diff all files that have changed.

Is it possible to get a interactive window with all the files that changed between two commits?

Empurple answered 9/11, 2012 at 8:21 Comment(2)
As ZyX mentions, it might be handy to add a command to fugitive to pull git diff --name-status {REV1}..{REV2} into a window. Or maybe there's some better workflow... will star and watch for any wizardry.Festivity
Note: This was also opened as fugitive GitHub issue #270 - Tim Pope replied with a workaround :Git diff branch1 branch2 --. This is not ideal though as it just shows a standard diff output.Pinto
C
4

As git does not support mercurial/bazaar status between two revisions neither fugitive can do it. Git has git diff --name-status instead, but simple grep reveals that this feature is never used in fugitive, except for checking of some file being clean (i.e. unmodified) when doing :Gw and friends.


If you are not afraid of somewhat experimental code, then you can try my aurum, it can bring you status window with

AuStatus rev topic wdrev development

and see vimdiff of specific file with C (closes status window by default, use let g:aurum_statwincmd='k' to avoid).

Note: with hg-git and vim compiled with +python aurum will be using more stable code as mercurial is the primary VCS I use.


Another idea is using vcscommand, mercurial/bazaar and hg-git/bzr-git. Then status will be viewed with

VCSStatus -r topic -r development

(mercurial, don’t remember how to do it in bazaar). I am unfamiliar with vcscommand though, so can’t say whether it offers as many interactive features in status buffer as fugitive or aurum do (seems it does not: nmap <buffer> in git status buffer shows nothing). The above code should work according to the documentation, but I have not tested.

Castoff answered 9/11, 2012 at 18:26 Comment(3)
Did you move aurum somewhere else? Its been deleted nowPinto
@Pinto I have update link in the answer: it was moved to gitlab since I have not found a good free mercurial hosting. Note though aurum was not maintained for quite a few years already.Castoff
I maintain a list of github alternatives and there's a few mercurial ones listed on there - I hear good things about sourcehut.orgPinto
P
3

As per Tim Pope's comment on the related fugitive GitHub issue #270 fugitive doesn't handle this and has no plans to.

However in searching this I came across Merginal which is based on Fugitive:

Merginal aims provide a nice inteface for dealing with Git branches. It offers interactive TUI for:

  • Viewing the list of branches
  • Checking out branches from that list
  • Creating new branches
  • Deleting branches
  • Merging branches
  • Rebasing branches
  • Solving merge conflicts
  • Renaming branches
  • Viewing git history for branches

...

Merginal is based on Fugitive, so it requires Fugitive.

What it doesn't quite make clear is that you can do a git diff between two branches.

After you have installed Merginal assuming you have main (master) branch and you want to diff develop branch against it to see the changes you are about to merge in Vim:

  1. :Git checkout main
  2. :Merginal
  3. You should see something like this in the left panel:
    Press ? for help
    
      develop
    * master
    
  4. Move your cursor over the develop branch
    1. If you look in the help ?
      gd   Open diff files buffer to diff
           against the branch under the
           cursor.
      
  5. Type gd (similar to any Fugitive command)
  6. This should should produce something like this in the left panel:
    Press ? for help
    
    === Diffing With: ===
    develop
    =====================
    
    M   README.md
    
  7. Then as with Fugitive you can press dv with the cursor over the file and it will open a vertical diffsplit:

Vim vertical diffsplit of README.md

Pinto answered 12/1, 2023 at 17:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.