Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git diff for added file [duplicate]

Tags:

git

diff

Normally I use git diff to check the changes of uncommited files (not yet git added) with the last commited one.

But after doing git add somefile (but not yet git commited), how to check the diff of that file?

like image 447
Kokizzu Avatar asked Mar 20 '15 06:03

Kokizzu


People also ask

Does git diff show added files?

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.

What does ++ mean in git diff?

When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.

How do I see changes after git add?

The git diff Command The --cached option displays the changes between the staging area and the HEAD . It shows what has been added to the staging area and staged for a commit. The git diff HEAD command shows all the changes made between the working directory and HEAD , including changes in the staging area.

How staged files are different?

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.


1 Answers

You can check

git diff --cached -- yourFile

That will diff between HEAd and the index.

http://images.abizern.org.s3.amazonaws.com/365git/Feb11/Git%20Diff%202.png

(from 365git.tumblr.com)

The -- helps separating the command from the parameters

See more on the double hyphen syntax in "Deleting a badly named git branch".

like image 169
VonC Avatar answered Oct 23 '22 04:10

VonC