裸目录上的gitk

gitk on bare directory

我曾经能够 运行 gitk 在远程服务器上的裸目录上。

我买了一台新的 Win10 机器,从 git-scm.com 安装了 git 这给了我 git 和 git Bash。 现在当我去同一个远程服务器时

 MINGW64 /t/git/MyProject (BARE:master)$ gitk

gitk says fatal: this operation mus be run in a work tree

我有点明白发生了什么,是的,我能做到$ git log

但是为什么之前可以呢?

But why did it work before?

最近 git

的行为发生了变化
git rev-parse --show-toplevel

打破了 gitk。这可以在 original bug report.

之后找到

我建议降级到版本 2.24。1.windows.2 这是最新的版本。

gitk says fatal: this operation mus be run in a work tree

使用 Git 2.29(2020 年第 4 季度),“gitk”应该可以在 运行 裸存储库中解决此问题。

参见 commit a99bc27 (15 Dec 2019), and commit f177c49 (02 Nov 2019) by Роман Донченко (SpecLad)
参见 commit 2faa6cd (09 Apr 2020) by Johannes Sixt (j6t)
参见 commit 113ce12 (11 Feb 2020) by Stefan Dotterweich (stefandtw)
参见 commit c1a6345 (15 Oct 2019) by Eric Huber (echuber2)
参见 commit d4247e0 (07 Dec 2019) by Kazuhiro Kato (kkato233)
参见 commit b8b6095 (12 Dec 2019) by Beat Bolli (bbolli)
参见 commit e2b9cb1 (03 Oct 2020), and commit e272a77 (23 Jan 2020) by Junio C Hamano (gitster)
参见 commit 6cd8049 (03 Oct 2020) by Paul Mackerras (paulusmack)
参见 commit e244588 (10 Sep 2020) by Denton Liu (Denton-L)
(由 Junio C Hamano -- gitster -- in commit 0cf28f6 合并,2020 年 10 月 5 日)

gitk: be prepared to be run in a bare repository

Helped-by: Eric Sunshine
Signed-off-by: Paul Mackerras

784b7e2f ("gitk: Fix "External diff" with separate work tree", 2011-04-04, Git v1.7.9-rc0) added an unconditional call to "git rev-parse --show-toplevel(man)" to set up a global variable quite early in the course of the program, so that the location of the working tree can later be known if/when the user chooses to run the external diff via the external_diff_get_one_file proc.
Before that change, the external diff code used to assume that the parent directory of ".git" directory is the top-level of the working tree.

Recent versions of git(man) however notices that "rev-parse --show-toplevel" executed in a bare repository is an error, which makes gitk stop, even before the user could attempt to run external diff.

Use the gitworktree helper introduced in 65bb0bda ("gitk: Fix the display of files when filtered by path", 2011-12-13, Git v1.7.10-rc3 -- merge), which is prepared to see failures from "rev-parse --show-toplevel" and other means it tries to find the top-level of the working tree instead to work around this issue.
The resulting value in $worktree global, when run in a bare repository, is bogus, but the code is not prepared to run external diff correctly without a working tree anyway ;-)