简体   繁体   English

为什么在 git 工作树中查找顶级目录时会出现“fatal: not a git repository...”?

[英]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.

相关问题 带有 git worktree 的 Docker:致命:不是 git 存储库 - Docker with git worktree: fatal: Not a git repository git 工作树中偶尔出现“致命:不是 git 存储库” - Occasional "fatal: not a git repository" in a git worktree 当我在git命令提示符下键入“ git add”时,收到致命消息,即不是git存储库。 - I am getting fatal message i.e not a git repository, when I am typing “git add .” in git command prompt. 为什么我收到错误“致命:'C:/ Program Files(x86)/ Git'在存储库外”当我从存储库中运行“git reset --hard~1”时? - Why am I getting error “fatal: 'C:/Program Files (x86)/Git' is outside the repository” when I run “git reset --hard ~1” from within the repository? 当我运行git archive时,为什么会出现“远程:致命:找不到路径:HEAD”错误? - Why am I getting “remote: fatal: path not found: HEAD” error when I run git archive? 我备份了一个git项目,并得到了“致命的:不是Git存储库” - I backed up a git project, and got “fatal: Not a Git Repository” 将subversion存储库转换为git,为什么我看到“致命:不是有效的对象名称”? - Converting a subversion repository to git, why am I seeing “fatal: not a valid object name”? 'git add'。 本地存储库位于工作树的子目录中时失败 - 'git add .' fails when local repository is in subdirectory of the worktree 当我 git 克隆:致命:似乎不是 git 存储库时 - When I git clone : fatal: does not appear to be a git repository 为什么致命:使用sbt-ghpages为有效的git项目发布网站时,不会出现git存储库错误? - Why does fatal: Not a git repository error show up when publishing site using sbt-ghpages for valid git project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM