I'd like to be able to run a command that opens up a git diff in vim, with a tab for each file in the diff set.
So if for example I've changed files foo.txt and bar.txt in my working tree and I ran the command I would see vim open with two tabs. The first tab would contain a side-by-side diff between foo.txt in my working tree and foo.txt in the repository, and the second tab would contain a side-by-side diff for bar.txt.
Anyone got any ideas?
You're taken to a page that shows the diffs as inline or unified for the file. Fortunately, there's a split button in the upper right hand corner that says Unified | Split. Clicking on Split portion of the button will show the before and after changes side by side, which is just my personal preference.
The git diff command displays the differences between files in two commits or between a commit and your current repository. You can see what text has been added to, removed from, and changed in a file. By default, the git diff command displays any uncommitted changes to your repository.
The diff can be done with git diff (followed by the filename or nothing if you want to see the diff of all modified files). But if you already did something like git add * , you have to undo with git restore --staged .
Adapted Benjamin Bannier + Dave Kirby's answer above for fugitive users.
Because I use fugitive.vim, I adapted the above for my most frequent use case, looking at the diff between the last 2 commits:
vim -p $(git diff --name-only HEAD~1 HEAD) -c "tabdo :Gdiff HEAD~1"
Loading all the changes into tabs is so much better than going through them sequentially with git difftool
.
The way I would do this (though it isn't a single command)
Open files with changes in new vim
tabs:
vim -p $(git diff --name-only)
For every buffer get the diff to your current HEAD with the vcscommand vim plugin
:VCSVimDiff
This gives a nice view of the difference, though not in patch form.
For anything else I would stick to git diff
.
EDIT
Like Dave writes below, steps 1 and 2 can be combined by using
vim -p $(git diff --name-only) -c "tabdo VCSVimDiff"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With