Normally I use git diff
to check the changes of uncommited files (not yet git add
ed) with the last commited one.
But after doing git add somefile
(but not yet git commit
ed), how to check the diff of that file?
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.
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.
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.
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.
You can check
git diff --cached -- yourFile
That will diff between HEAd and the index.
(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".
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