7

I'm in a git repo in which some changes have been made. So I first did a git status, which shows one file changed. I then did a git diff to view the changes, but that doesn't output anything at all (see output below), not even a mode change or anything.

Does anybody know why git diff doesn't output anything while there are clearly some changes? All tips are welcome!

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   src/app/models/VariablePosition.py

no changes added to commit (use "git add" and/or "git commit -a")
$ git diff
$

[EDIT] It was asked what the output of git config core.filemode is:

$ git config core.filemode
true
kramer65
  • 50,427
  • 120
  • 308
  • 488
  • 3
    @FredericHenri nonsense, after committing it will not be shown in git diff, because then you will be diffing against the commit you just made – Tim Sep 08 '15 at 14:13
  • 1
    @Tim, read this http://stackoverflow.com/questions/10039747/git-how-to-view-file-diff-before-commit – Frederic Henri Sep 08 '15 at 14:13
  • 3
    @FredericHenri Tim is correct, plain `$ git diff` would show the differences between the working directory and the index. – Thomas Stringer Sep 08 '15 at 14:15
  • @FredericHenri not sure what you mean to say with that link, that one is about diff before committing it seems – Tim Sep 08 '15 at 14:17
  • Once the changes are committed there won't be a diff; diff should show diffs before and after added, but not after the commit. – Dave Newton Sep 08 '15 at 14:21
  • sorry abuse language on my first comment, I meant added to staging area, guess working with an IDE gives me wrong impression – Frederic Henri Sep 08 '15 at 14:25
  • How exactly did you modify this file? Did you just change permission of this file? What `git` version do you use? – Arkadiusz Drabczyk Sep 08 '15 at 14:29
  • One possible explanation is that only the file's permissions have changed and `git diff` is configured to not show permissions changes. What does `git config core.filemode` tell you? – jub0bs Sep 08 '15 at 14:29
  • @Jubobs I wondered that myself but get full output: `diff --git a/build.xml b/build.xml old mode 100644 new mode 100755` not sure if that's a newer git feature – bcmcfc Sep 08 '15 at 14:35
  • 2
    @bcmcfc Set `core.filemode` to `false` and `git diff` will not show changes about files whose only changes are permission changes. – jub0bs Sep 08 '15 at 14:37
  • Ah, that makes sense. Thanks – bcmcfc Sep 08 '15 at 14:50
  • @Jubobs - The output of `git config core.filemode` is `true`.. :S – kramer65 Sep 08 '15 at 16:33

2 Answers2

0

Not sure if your problem, but I had this problem on a Mac with the config files copied from my Linux machine.

The problem seemed to be with the pager, so I looked at my LESS environment variables, and it looks like it was a problem with the --quit-if-one-screen option, as described here:

https://unix.stackexchange.com/q/107315

Apparently it goes to the alternate screen and loses the output when it comes back. An answer says that it was fixed in version 530. (My Linux machine had less 551, while the Mac on Big Sur had version 487.)

I removed the option from the variable, and git diff came back to life.

Gringo Suave
  • 29,931
  • 6
  • 88
  • 75
-1

Your file is still in working directory. After using git add filename it will go to staging area and after committing it will include in git repository. Then only git will take into account and show as diff. Also try using git diff branchname. As by default, git diff compares with master and if you are already on master, it won't show any diff because that's what it is comparing with.

  • Your theory doesn't apply here. The file shows as *modified* in git status, which means it was already tracked – Tim Oct 23 '15 at 09:59