git diff [ --cached ] 显示没有变化,但我发誓有一些
Posted
技术标签:
【中文标题】git diff [ --cached ] 显示没有变化,但我发誓有一些【英文标题】:git diff [ --cached ] shows no change, but I swear there are some 【发布时间】:2018-11-15 19:00:19 【问题描述】:我的 git-diff 刚刚坏了!可能是什么问题?
$ 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
好的,让我们尝试一个新的存储库
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
哇?这可能是一个问题?
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
【问题讨论】:
【参考方案1】:确实,git diff
应该会显示您的更改,但有时不会因为寻呼机损坏。要检查这一点,请执行以下操作:
git --no-pager diff
如果显示某些内容,请将您的寻呼机设置为简单的内容:
git config --global core.pager less
在您提供的配置中,您的寻呼机是:
core.pager=less -E
根据man less
-E or --QUIT-AT-EOF Causes less to automatically exit the first time it reaches end-of-file.
这意味着,如果您的更改小于终端高度,less
会将它们分页并在 备用屏幕缓冲区 开启时立即退出:
在 VT102 模式下,有转义序列来激活和停用备用屏幕缓冲区,该缓冲区与窗口的显示区域大小相同。激活后,当前屏幕将被保存并替换为备用屏幕。在恢复正常屏幕之前,禁用从窗口顶部滚动的行的保存。 xterm 的 termcap(5) 条目允许可视化编辑器 vi(1) 切换到备用屏幕进行编辑并在退出时恢复屏幕。弹出菜单项让您可以轻松地在正常屏幕和备用屏幕之间切换以进行剪切和粘贴。
(source)
可以使用terminfo(5)
打开/关闭此选项。
【讨论】:
如果您(像我一样)在终端模拟器或通过 termcap/terminfo 禁用整个“备用页面/屏幕”crud,则退出端不再是问题。 :-) 我建议将@torek 的评论包含在答案正文中,因为基本上答案很好,但错过了整个拼图变得完整的最后一部分;-) More info 关于“备用屏幕”的真正含义。还有this. @kostix 您提供的链接很有用,我将其包含在此答案中。 相关:***.com/q/4734844/5470596、***.com/q/14564946/5470596、***.com/q/29428026/5470596 和 ***.com/q/6050836/5470596以上是关于git diff [ --cached ] 显示没有变化,但我发誓有一些的主要内容,如果未能解决你的问题,请参考以下文章