Git:“减少”崩溃git diff 与“终端”的比较来自维姆?

发布于 2025-01-15 22:36:48 字数 2307 浏览 4 评论 0原文

环境

❯ sw_vers
ProductName:    macOS
ProductVersion: 11.6.1
BuildVersion:   20G224

❯ git --version
git version 2.31.1

❯ less -V
less 590 (PCRE2 regular expressions)
Copyright (C) 1984-2021  Mark Nudelman

❯ vi --version
VIM - Vi IMproved 8.2 (2019 Dec 12, 빌드한 날짜 Feb 22 2022 22:17:00)
macOS 버젼 - x86_64
포함된 패치: 1-4450
Compiled by Homebrew
...
(omitted details)

我想在 vim 的垂直窗口中使用右侧的 git diff 输出编写提交消息。

预期

在某些 git 工作目录中,我可以使用以下命令进行预期的操作:

❯ vim "+bo vert ter git diff" "+winc p" .git/COMMIT_EDITMSG
  • :bo[tright] vert[ical] ter[minal] git diff: run git diff in a新终端,右侧垂直窗口。
  • :winc[md] p: 返回上一个窗口,在其中编辑提交消息。

问题

但是当 git commit 与上面的 GIT_EDITOR 变量一样时,它会失败:

# [alias] cm = commit -as
❯ GIT_EDITOR='vim "+bo vert ter git diff" "+winc p"' git cm

使用 GIT_TRACE,我假设 vim 和 less from < code>git diff:

❯ GIT_TRACE=2 GIT_EDITOR='vim "+bo vert ter git diff" "+winc p"' git cm
23:21:41.599932 git.c:733               trace: exec: git-cm
23:21:41.600666 run-command.c:667       trace: run_command: git-cm
23:21:41.601180 git.c:390               trace: alias expansion: cm => commit -as
23:21:41.601190 git.c:794               trace: exec: git commit -as
23:21:41.601194 run-command.c:667       trace: run_command: git commit -as
23:21:41.607190 git.c:447               trace: built-in: git commit -as
힌트: 편집기가 파일을 닫기를 기다리는 중입니다... 23:21:41.620256 run-command.c:667       trace: run_command: GIT_INDEX_FILE=/Users/hansuk/dotfiles/.git/index.lock 'vim "+bo vert ter git diff" "+wincmd p"' /Users/hansuk/dotfiles/.git/COMMIT_EDITMSG
(-------- Above here, printed in the terminal where the `git commit` is running --------)
(-------- Followings are printed in the vim's right vertical terminal ------------------)
23:21:41.745108 git.c:447               trace: built-in: git diff
23:21:41.746732 run-command.c:667       trace: run_command: unset GIT_PAGER_IN_USE; LESS=FRX LV=-c less

我该如何修复它?我需要挖掘 git 的代码吗?

Environments

❯ sw_vers
ProductName:    macOS
ProductVersion: 11.6.1
BuildVersion:   20G224

❯ git --version
git version 2.31.1

❯ less -V
less 590 (PCRE2 regular expressions)
Copyright (C) 1984-2021  Mark Nudelman

❯ vi --version
VIM - Vi IMproved 8.2 (2019 Dec 12, 빌드한 날짜 Feb 22 2022 22:17:00)
macOS 버젼 - x86_64
포함된 패치: 1-4450
Compiled by Homebrew
...
(omitted details)

I'd like to write commit messages with git diff's output at right, in a vertical window of vim.

Expected

In some git working dir, I can make what I expected with:

❯ vim "+bo vert ter git diff" "+winc p" .git/COMMIT_EDITMSG
  • :bo[tright] vert[ical] ter[minal] git diff: run git diff in a new termial, vertical window at right.
  • :winc[md] p: and come back to the previous window, where to edit the commit message.

Problem

But when git commit with GIT_EDITOR variables like above, it fails:

# [alias] cm = commit -as
❯ GIT_EDITOR='vim "+bo vert ter git diff" "+winc p"' git cm

With GIT_TRACE, I assumed there is a conflict between vim and less from git diff:

❯ GIT_TRACE=2 GIT_EDITOR='vim "+bo vert ter git diff" "+winc p"' git cm
23:21:41.599932 git.c:733               trace: exec: git-cm
23:21:41.600666 run-command.c:667       trace: run_command: git-cm
23:21:41.601180 git.c:390               trace: alias expansion: cm => commit -as
23:21:41.601190 git.c:794               trace: exec: git commit -as
23:21:41.601194 run-command.c:667       trace: run_command: git commit -as
23:21:41.607190 git.c:447               trace: built-in: git commit -as
힌트: 편집기가 파일을 닫기를 기다리는 중입니다... 23:21:41.620256 run-command.c:667       trace: run_command: GIT_INDEX_FILE=/Users/hansuk/dotfiles/.git/index.lock 'vim "+bo vert ter git diff" "+wincmd p"' /Users/hansuk/dotfiles/.git/COMMIT_EDITMSG
(-------- Above here, printed in the terminal where the `git commit` is running --------)
(-------- Followings are printed in the vim's right vertical terminal ------------------)
23:21:41.745108 git.c:447               trace: built-in: git diff
23:21:41.746732 run-command.c:667       trace: run_command: unset GIT_PAGER_IN_USE; LESS=FRX LV=-c less

How could I fix it? Do I need to dig the git's codes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文