How do I do this? After doing changes via git config
I can diff my staged and committed changes with vimdiff but when I do git show
I still see the diff in old plain style. How do I make this work for git show
as well?
Switch between diff window Please note that, we have to press Ctrl + w 2 times.
Vimdiff can be run from the command-line with vimdiff file1 file2 [file3 [file4]] . This actually starts Vim in diff mode -- the previous command is actually equivalent to vim -d file1 file2 [file3 [file4]] . Vim requires a diff command to be available for this to work.
Your file is already staged to be committed. You can show it's diff using the --cached option of git. To unstage it, just do what git status suggests in it's output ;) You can check The Git Index For more info.
The default git show
with no parameter as well as git show <object>
display changes to all files within a commit. Since vimdiff can only compare a single file at a time, you cannot use it with these options.
However git show <object> -- <file>
shows the changes to a single file within a commit. You can display the changes in vimdiff by running difftool
instead:
git difftool SHA~:SHA -- <file>
If you need more flexibility, you can always use git show
to fetch specific versions of a file and pass them into vimdiff via Process Substituion
export FILE=path/to/file; vimdiff <(git show SHA1:$FILE) <(git show SHA2:$FILE)
With git show
you can show objects like commits (see the man page for reference). So you don't show a diff of two files, but changes in (maybe multiple) files. So there are not two files, which can be compared. But that is exactly what vimdiff does, it opens two files side-by-side and highlights differences.
When you use git difftool
or something like that it will create files for both sides of the diff and use the tool (in your case vimdiff) to compare them. git show
does not create those files, so its output can't be shown by vimdiff.
tl;dr: git show
is a tool to display git objects, not to create diffs, so its output can't be shown as a diff using vimdiff.
What you might want to do is to use git difftool
. It will open gvimdiff for every modified file.
You can use the usual options of git diff
to compare different commits.
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