Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - some files are marked as changed but 'git diff' doesn't show anything

Tags:

git

I am quite new to Git, thus maybe I am missing something here.

dan@one:/var/www/$ git status -s M  GoogleChromeExtension.js M  ApiClient.js 

So clearly 2 files have been changed.
But when I run:

git diff 

no output is shown. I was expecting to get the changes between my working copy and the latest commit.

I am sure yesterday everything was working as expecting...

Is it maybe because I haven't been pushing the changes to the remote server?

P.S.: I am using GitHub

Thanks,
Dan

like image 589
Dan Avatar asked May 18 '11 20:05

Dan


People also ask

Why git diff does not show changes?

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.

How do I see changes in git diff?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.

How do I remove unchanged files in git?

Remove every file from Git's index. git rm --cached -r .

How does git detect changed files?

To determine whether a file has changed, Git compares its current stats with those cached in the index. If they match, then Git can skip reading the file again.


1 Answers

Do a git diff --cached - it compares the HEAD and index, ie stuff added for commit.

Just a git diff is between index and working directory, so if all the changes have been staged for commit, you won' see anything in git diff

The third form is git diff <commit> which compares working directory and commit. So doing git diff HEAD will also give you the diff that you want as well.

like image 79
manojlds Avatar answered Sep 20 '22 14:09

manojlds