YSC
YSC

Reputation: 40080

git diff [ --cached ] shows no change, but I swear there are some

My git-diff just broke! What could be the matter?

$ sh # start an unmodified shell

 

sh-4.2$ git --version
git version 2.16.2

 

sh-4.2$ git status --short
 M CMakeLists.txt
?? CMakeLists.txt.bak

 

sh-4.2$ git diff
sh-4.2$ echo $?
0

 

sh-4.2$ git add -p
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f527ae0..231dc72 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -101,7 +101,7 @@
 actual diff removed
 but this is what U'd expect to see
+when doing git diff
 some context
 and end of diff
Stage this hunk [y,n,q,a,d,/,e,?]? n

Ok, let's try on a fresh repository

sh-4.2$ git init
Initialized empty Git repository in /tmp/tmp.git/.git/
sh-4.2$ echo 42 > answer
sh-4.2$ git add answer 
sh-4.2$ git commit -m"init"
[master (root-commit) 24b402c] init
 1 file changed, 1 insertion(+)
 create mode 100644 answer
sh-4.2$ echo '7*6' > answer 
sh-4.2$ git status --short
 M answer
sh-4.2$ git diff
sh-4.2$ git add -p
diff --git a/answer b/answer
index d81cc07..e2d42c8 100644
--- a/answer
+++ b/answer
@@ -1 +1 @@
-42
+7*6
Stage this hunk [y,n,q,a,d,/,e,?]? n

Whaaaat? It might be a conf-trouble?

sh-4.2$ git config --list
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
core.symlinks=true
core.autocrlf=false
core.fscache=true
core.pager=less -E
core.editor=emacs
user.name=YSC
user.email=YSC@***
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
color.ui=auto
help.format=html
rebase.autosquash=true
alias.st=status -s
alias.l=log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(black)%s%C(reset) %C(magenta)- %an%C(reset)%C(auto)%d%C(reset)' --all
http.sslverify=false
merge.tool=ediff
mergetool.ediff.trustexitcode=false
mergetool.ediff.cmd=emacs --eval "     (progn       (defun ediff-write-merge-buffer ()         (let ((file ediff-merge-store-file))           (set-buffer ediff-buffer-C)           (write-region (point-min) (point-max) file)           (message \"Merge buffer saved in: %s\" file)           (set-buffer-modified-p nil)           (sit-for 1)))       (setq ediff-quit-hook 'kill-emacs             ediff-quit-merge-hook 'ediff-write-merge-buffer)       (ediff-merge-files-with-ancestor \"$LOCAL\" \"$REMOTE\"                                        \"$BASE\" nil \"$MERGED\"))"
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

Upvotes: 2

Views: 226

Answers (1)

YSC
YSC

Reputation: 40080

Indeed, git diff should show your changes, but sometimes doesn't due to a bad pager. To check that, do:

git --no-pager diff

If it shows something, set your pager back to something simple:

git config --global core.pager less

In the configuration you gave, your pager was:

core.pager=less -E

According to man less

  -E or --QUIT-AT-EOF
          Causes  less  to  automatically  exit the first time it
          reaches end-of-file.

This means if your changes were smaller than your terminal height, less would page them and immediately exit if the alternate screen buffer is on:

In VT102 mode, there are escape sequences to activate and deactivate an alternate screen buffer, which is the same size as the display area of the window. When activated, the current screen is saved and replaced with the alternate screen. Saving of lines scrolled off the top of the window is disabled until the normal screen is restored. The termcap(5) entry for xterm allows the visual editor vi(1) to switch to the alternate screen for editing and to restore the screen on exit. A popup menu entry makes it simple to switch between the normal and alternate screens for cut and paste.

(source)

This option can be turned ON/OFF with terminfo(5).

Upvotes: 3

Related Questions