Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run `git diff --staged` with Fugitive?

Tags:

vim-fugitive

The command :Gdiff is equivalent to running git diff on that file.

What's the equivalent for git diff --staged or git diff --cached?

like image 638
Flimm Avatar asked Mar 14 '13 11:03

Flimm


People also ask

What is the difference between git diff and git diff -- staged?

git diff --staged will only show changes to files in the "staged" area. git diff HEAD will show all changes to tracked files. If you have all changes staged for commit, then both commands will output the same.

How do I see staged files in git?

If your changes are already staged, then there's no difference to show. But there's a command line option that will show you staged changes if you specify it: git diff --staged . With the --staged option, git diff will compare your staged changes against the previous commit.

What is the use of git diff -- staged?

The git diff command allows us to track the changes that are staged but not committed. We can track the changes in the staging area. To check the already staged changes, use the --staged option along with git diff command.


1 Answers

I've found a way to do this. Run :Gstatus, you should get a window with contents like the following:

# On branch master # Changes to be committed: #   (use "git reset HEAD <file>..." to unstage) # #   modified:   example.txt # 

Scroll down to the staged file, example.txt, and press Shift+D. This will open a diff view, comparing what's in HEAD and what's in the index. You'll notice on the bar on the bottom that both the filenames are special Fugitive filenames.

Also while in Gstatus preview window, you can press g?, which will list all the mappings valid in the current context.

like image 60
Flimm Avatar answered Sep 19 '22 13:09

Flimm