git diff가 호출기를 사용하지 못하도록하려면 어떻게해야합니까?
전달할 명령 줄 스위치 git diff
와 less
기본적으로 호출기 를 사용하는 다른 명령이 있습니까?
나는 그것을 cat으로 파이프 할 수 있다는 것을 알고 있지만 모든 구문 강조 표시를 제거합니다.
나는 전역 .gitconfig의 호출기를 cat by GITPAGER=cat
(또는 이와 비슷한 것)로 설정할 수 있다는 것을 알고 있습니다 . 그러나 나는 때때로 호출기를 원합니다 (diff의 크기에 따라 다름).
그러나 명령 줄 스위치가 있으면 선호합니다. 매뉴얼 페이지를 통해 찾을 수 없습니다.
--no-pager
git에게 호출기를 사용하지 않도록 지시합니다. -F
less에 옵션 을 전달하면 출력이 단일 화면에 맞는 경우 페이지가 표시되지 않습니다.
용법:
git --no-pager diff
주석의 다른 옵션은 다음과 같습니다.
# set an evaporating environment variable to use cat for your pager
GIT_PAGER=cat git diff
# tell less not to paginate if less than a page
export LESS="-F -X $LESS"
# ...then git as usual
git diff
이전 답변에서 언급했듯이 -F
less에 옵션을 전달하면 콘텐츠가 한 화면 미만인 경우 종료되지만 그렇게 한 후에 화면이 재설정되고 콘텐츠가 표시되지 않으면 -X
옵션이 해당 동작을 제거합니다. 따라서 다음을 사용하여 콘텐츠 양에 따라 조건부 페이징을 활성화합니다.
git config --global --replace-all core.pager "less -F -X"
사용하다
git config --global core.pager cat
모든 저장소의 모든 명령에 대한 호출기를 제거합니다.
pager.<cmd>
대신에 설정 을 사용하여 단일 git 하위 명령에 대한 페이징을 비활성화 core.pager
할 수 있으며 git 저장소별로 설정을 변경할 수 있습니다 (생략 --global
).
자세한 내용을 확인 man git-config
하고 검색 pager.<cmd>
하십시오.
문서의 최근 변경 사항에서는에 대한 기본 옵션을 제거하는 다른 방법이 언급되어 less
있습니다 ( "기본 옵션"은 FRSX
).
이 질문에 대해서는 (git 1.8+)
git config --global --replace-all core.pager 'less -+F -+X'
예를 들어 Dirk Bester 는 의견에서 다음 과 같이 제안 합니다 .
export LESS="$LESS -FRXK"
그래서 Ctrl-Cquit from
less
.
Wilson F 는 의견 과 질문 에서 다음 과 같이 언급 합니다.
less는 가로 스크롤을 지원하므로 줄이 잘릴 때 less는 quit-if-one-screen을 비활성화하여 사용자가 텍스트를 왼쪽으로 스크롤하여 잘린 부분을 볼 수 있습니다.
이러한 수정 사항은 " 항상 호출기를 사용git diff
"(주석 참조)에 설명 된대로 git 1.8.x에서 이미 볼 수 있습니다 . 그러나 문서는 방금 변경 되었습니다 (git 1.8.5 또는 1.9, Q4 2013 ).
Git 명령에서 사용할 텍스트 뷰어 (예 : 'less').
값은 쉘에서 해석됩니다.선호하는 순서는 다음과 같습니다.
$GIT_PAGER
환경 변수- 그런 다음
core.pager
구성,- 다음
$PAGER
,- 그런 다음 컴파일 타임에 선택된 기본값 (보통 'less').
때
LESS
환경 변수를 설정하고, 그것을 힘내를 설정FRSX
(만약LESS
환경 변수 설정, 힘내 전혀 변경하지 않음).If you want to selectively override Git's default setting for
LESS
, you can setcore.pager
to e.g.less -+S
.
This will be passed to the shell by Git, which will translate the final command toLESS=FRSX less -+S
. The environment tells the command to set theS
option to chop long lines but the command line resets it to the default to fold long lines.
See commit 97d01f2a for the reason behind the new documentation wording:
config: rewrite core.pager
documentation
The text mentions
core.pager
andGIT_PAGER
without giving the overall picture of precedence. Borrow a better description from thegit var
(1) documentation.The use of the mechanism to allow system-wide, global and per-repository configuration files is not limited to this particular variable. Remove it to clarify the paragraph.
Rewrite the part that explains how the environment variable
LESS
is set to Git's default value, and how to selectively customize it.
Note: commit b327583 (Matthieu Moy moy
, April 2014, for git 2.0.x/2.1, Q3 2014) will remove the S by default:
pager: remove 'S' from $LESS by default
By default, Git used to set
$LESS
to-FRSX
if$LESS
was not set by the user.
TheFRX
flags actually make sense for Git (F
andX
because sometimes the output Git pipes to less is short, andR
because Git pipes colored output).
TheS
flag (chop long lines), on the other hand, is not related to Git and is a matter of user preference. Git should not decide for the user to changeLESS
's default.More specifically, the
S
flag harms users who review untrusted code within a pager, since a patch looking like:-old code; +new good code; [... lots of tabs ...] malicious code;
would appear identical to:
-old code; +new good code;
Users who prefer the old behavior can still set the $LESS environment variable to
-FRSX
explicitly, or set core.pager to 'less -S
'.
The documentation will read:
The environment does not set the
S
option but the command line does, instructing less to truncate long lines.
Similarly, settingcore.pager
toless -+F
will deactivate theF
option specified by the environment from the command-line, deactivating the "quit if one screen
" behavior ofless
.
One can specifically activate some flags for particular commands: for example, settingpager.blame
toless -S
enables line truncation only forgit blame
.
You can disable/enable pagers for specific outputs in global config as well:
git config --global pager.diff false
Or to set the core.pager option, just provide an empty string:
git config --global core.pager ''
This is better in my opinion than setting it to cat
as you say.
Regarding the disabled color when piping:
Use --color
to avoid that coloring is disabled.
git diff --color | less -R
Or configure it forced on (in e.g. .gitconfig):
[color]
ui = on
git diff | less -R
For non-color tools, then use:
git diff --no-color | some-primitive-tool
Exporting environment variable LESS=-R
(in e.g. .bashrc) turns on color support by default in "less":
git diff | less
This worked for me with git version 2.1.4 in Linux:
git config --global --replace-all core.pager cat
This makes git use cat
instead of less
. cat
just dumps the output of diff
to the screen with out any paging.
You can add an alias to diff with its own pager with pager.alias, like so:
[alias]
dc = diff
dsc = diff --staged
[pager]
dc = cat
dsc = cat
This will keep the color on and use 'cat' as the pager when invoked at 'git dc'.
Also, things not to do:
- use --no-pager in your alias. Git (1.8.5.2, Apple Git-48) will complain that you are trying to modify the environment.
- use a shell with !sh or !git. This will bypass the environment error, above, but will reset your working directory (for the purposes of this command) to the top-level git dir, so any references to a local file will not work if you are already in a subdir of your repo.
I have this hunk in my .gitconfig
and it seems to work fine (disabled for both diff and show):
[pager]
diff = false
show = false
I like to disable paging from time to time, when I know the output is not very long. For this, I found a neat trick using git aliases:
git config --global --add alias.n '!git --no-pager'
Or add the following to the [alias]
section of ~/.gitconfig:
n = !git --no-pager
This means that you can use the prefix n
to turn off paging for any git command, i.e.:
git n diff # Show the diff without pager
git n log -n 3 # Show the last 3 commits without pager
git n show v1.1 # Show information about a tag
For a quick-and-dirty script I wrote, I did it this way:
PAGER=cat git diff ...
As it says on man git, you can use --no-pager
on any command.
I use it on:
git --no-pager diff
git --no-pager log --oneline --graph --decorate --all -n 10
Then use an alias to avoid using (and remembering) long commands.
if you user the oh-my-zsh, in the ~/.oh-my-zsh/lib/misc.zsh file,comment this line
env_default 'LESS' '-R'
For Windows it is:
git config --global core.pager ""
This will turn off paging for everything in git
, including the super annoying one in git branch
.
git -P diff
Or --no-pager
.
BTW: To preserve colour with cat
git diff --color=always | cat
참고URL : https://stackoverflow.com/questions/2183900/how-do-i-prevent-git-diff-from-using-a-pager
'Nice programing' 카테고리의 다른 글
datetime을 날짜로 어떻게 변환합니까 (Python에서)? (0) | 2020.10.03 |
---|---|
ISO 8601 형식의 날짜를 어떻게 구문 분석합니까? (0) | 2020.10.03 |
함수 내부의 정적 변수에 해당하는 Python은 무엇입니까? (0) | 2020.10.03 |
SQL Server 테이블에 대한 INSERT 문을 자동 생성하는 가장 좋은 방법은 무엇입니까? (0) | 2020.10.03 |
`require ':로드 할 파일 없음 — mkmf (LoadError) (0) | 2020.10.03 |