如果我这样做less somefile.txt或man bash(内部使用less),它会显示内容,但按后Q,内容消失。
git diff也使用less,但输出保留在控制台中。我怎样才能使git行为与 相同man?
目前的行为
me@mypc:~$ git diff
# I look at the diff and then press q. But it's all printed to the console
diff --git a/somefile.txt b/somefile.txt
...
...
...
me@mypc:~$
me@mypc:~$ less somefile.txt
# I look at the file content, but after I press q, console appears and nothing is printed there
me@mypc:~$
Run Code Online (Sandbox Code Playgroud)
我意识到 git 的行为就像less -X,那么如果没有这个选项,我如何强制 git 少运行呢?
这是效果less -F -X;见.core.pagergit-config(1)
从less(1):
-F or --quit-if-one-screen\n Causes less to automatically exit if the entire file can be dis\xe2\x80\x90\n played on the first screen.\n\n -X or --no-init\n Disables sending the termcap initialization and deinitialization\n strings to the terminal. This is sometimes desirable if the\n deinitialization string does something unnecessary, like clear\xe2\x80\x90\n ing the screen.\nRun Code Online (Sandbox Code Playgroud)\n\nPart of the "init" mentioned here involves switching to the alternate screen, so that the main screen is preserved.
\n\nFrom git-config(1):
core.pager\n Text viewer for use by Git commands (e.g., less). The value is\n meant to be interpreted by the shell. The order of preference is\n the $GIT_PAGER environment variable, then core.pager configuration,\n then $PAGER, and then the default chosen at compile time (usually\n less).\n\n When the LESS environment variable is unset, Git sets it to FRX (if\n LESS environment variable is set, Git does not change it at all).\n If you want to selectively override Git\xe2\x80\x99s default setting for LESS,\n you can set core.pager to e.g. less -S. This will be passed to the\n shell by Git, which will translate the final command to LESS=FRX\n less -S. The environment does not set the S option but the command\n line does, instructing less to truncate long lines. Similarly,\n setting core.pager to less -+F will deactivate the F option\n specified by the environment from the command-line, deactivating\n the "quit if one screen" behavior of less. One can specifically\n activate some flags for particular commands: for example, setting\n pager.blame to less -S enables line truncation only for git blame.\n\n Likewise, when the LV environment variable is unset, Git sets it to\n -c. You can override this setting by exporting LV with another\n value or setting core.pager to lv +c.\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
971 次 |
| 最近记录: |