[英]Why am I getting `fatal: not a git repository...` when looking up toplevel dir in a git worktree?
I'm currently tinkering with git worktrees and suddenly ran into a problem.我目前正在修改 git worktrees,突然遇到了一个问题。 I tried both approaches with and without bare clones described here:
我尝试了使用和不使用此处描述的裸克隆的两种方法:
https://infrequently.org/2021/07/worktrees-step-by-step/ and https://svij.org/blog/2017/04/14/mit-git-worktree-mehrere-arbeitsverzeichnisse-managen/ (ger) https://infrequently.org/2021/07/worktrees-step-by-step/和https://svij.org/blog/2017/04/14/mit-git-worktree-mehrere-arbeitsverzeichnisse-managen/ ( ger)
and my current directory setup looks like this:我当前的目录设置如下所示:
$ tree -aL 1
.
├── worktree-branch1
├── worktree-master
└── .git
when I'm entering eg worktree-master
and run git rev-parse --show-toplevel
using git version 2.17.1
it points me correctly to the worktree root.当我输入例如
worktree-master
并使用 git 版本2.17.1
运行git rev-parse --show-toplevel
它正确地将我指向工作树根。
When I now do the same inside a Docker-container based on ubuntu:20.04
running version 2.25.1
of git I'm getting当我现在在基于
ubuntu:20.04
运行 git 2.25.1
版的 Docker 容器中执行相同2.25.1
,我得到了
$ git rev-parse --show-toplevel
fatal: not a git repository: /home/me/git-project/.git/worktrees/worktree-master
Is this an issue with this specific version?这是这个特定版本的问题吗? Or does git make use of some strange magic which does not work inside a Docker container?
或者 git 是否使用了一些在 Docker 容器中不起作用的奇怪魔法?
Is there a workaround for this to get the worktrees toplevel dir?是否有解决方法来获取工作树顶级目录?
Ok, I got it.好,我知道了。
Problem was, I'm running the container using something like问题是,我正在使用类似的东西运行容器
REPO_DIR="$(git rev-parse --show-toplevel)"
docker run -it --rm -v "$(REPO_DIR):$(REPO_DIR)" ubuntu:20.04 bash
inside the worktree, which worked without worktrees, since all git needs was located inside ./.git
.在没有工作树的情况下工作的工作树内部,因为所有 git 需求都位于
./.git
。
Now - with the worktree - git tries to access ../.git
which was not available given the command I posted.现在 - 使用工作树 - git 尝试访问
../.git
,根据我发布的命令,该文件不可用。
The optimization I need now would be to get the parent directory both the worktree and the bare clone share (which usually should be a parent directory of REPO_DIR
).我现在需要的优化是获取工作树和裸克隆共享的父目录(通常应该是
REPO_DIR
的父目录)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.