git diff [–cached]显示没有变化,但我发誓有一些


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

我的Git Diff刚坏了!怎么了?

1
$ sh # start an unmodified shell

nbsp;

1
2
sh-4.2$ git --version
git version 2.16.2

nbsp;

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

nbsp;

1
2
3
sh-4.2$ git diff
sh-4.2$ echo $?
0

nbsp;

1
2
3
4
5
6
7
8
9
10
11
12
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

好吧,让我们试试新的存储库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

什么?这可能是一个确认问题?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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


确实,git diff应该显示您的更改,但有时不是由于错误的传呼机。要检查,请执行以下操作:

1
git --no-pager diff

如果它显示了某些内容,请将寻呼机设置回简单的内容:

1
git config --global core.pager less

在您提供的配置中,您的寻呼机是:

1
core.pager=less -E

按人少说

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

这意味着,如果您的更改小于终端高度,less将对其进行分页,并在备用屏幕缓冲区打开时立即退出:

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)

此选项可以通过terminfo(5)打开/关闭。