简体   繁体   English

Git 错误“致命:GIT_WORK_TREE(或 --work-tree=<directory> ) 不允许不指定 GIT_DIR (或 --git-dir=<directory> )”

[英]Git error "fatal: GIT_WORK_TREE (or --work-tree=<directory>) not allowed without specifying GIT_DIR (or --git-dir=<directory>)"

I have GIT_WORK_TREE set to .我将GIT_WORK_TREE设置为. and GIT_DIR set to .git .GIT_DIR设置为.git When I run git init --bare , I get the following error:当我运行git init --bare ,出现以下错误:

fatal: GIT_WORK_TREE (or --work-tree=<directory> ) not allowed without specifying GIT_DIR (or --git-dir=<directory> )致命:在不指定GIT_DIR (或--git-dir=<directory> )的情况下不允许GIT_WORK_TREE (或--work-tree=<directory> --git-dir=<directory>

What's up with that?那是怎么回事? I suspect that it might have something to do with GIT_DIR being set to .我怀疑它可能与GIT_DIR设置为. (maybe it considers GIT_DIR unset if it points to the current working directory?). (如果它指向当前工作目录,它可能认为GIT_DIR设置?)。 Regardless, it would be great to have this behave properly so I don't have to unset GIT_WORK_TREE every time I want to initialize a Git repo.无论如何,让它正确运行会很棒,这样我每次想初始化 Git 存储库时都不必取消设置 GIT_WORK_TREE。

This error message comes from builtin/init-db.c此错误消息来自builtin/init-db.c

    /*
     * GIT_WORK_TREE makes sense only in conjunction with GIT_DIR
     * without --bare.  Catch the error early.
     */
    git_dir = getenv(GIT_DIR_ENVIRONMENT);
    work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
    if ((!git_dir || is_bare_repository_cfg == 1) && work_tree)
        die(_("%s (or --work-tree=<directory>) not allowed without "
              "specifying %s (or --git-dir=<directory>)"),

So on Unbuntu, unset GIT_WORK_TREE just before doing a git init --bare .所以在 Unbuntu 上,在执行git init --bare之前取消设置GIT_WORK_TREE
See " Unset an environmental variable for a single command ":请参阅“为单个命令取消设置环境变量”:

env -u GIT_WORK_TREE git init --bare
# or
GIT_WORK_TREE=  git init --bare

I'm adding remote on windows perfectly我正在完美地在 Windows 上添加遥控器

git init --bare is not "adding remote", so you need to check what command triggers that error message. git init --bare不是“添加远程”,因此您需要检查触发该错误消息的命令。


On Windows, use cmd /V/ /C as explained here :在 Windows 上,使用cmd /V/ /C如下所述

cmd /V /C "set "GIT_WORK_TREE=" && git init --bare"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在smartgit中设置--work-tree或--git-dir? - How to set --work-tree or --git-dir in smartgit? 如何在子模块中检测父 Git 存储库的正确 GIT_DIR 和 GIT_WORK_TREE - How to detect correct GIT_DIR and GIT_WORK_TREE of the parent Git repository in a submodule 如何在维护多个存储库时设置GIT_DIR和GIT_WORK_TREE - How to set GIT_DIR & GIT_WORK_TREE when maintaining multiple repositories 使用gulp-git时如何使用git-dir和工作树 - Using gulp-git how to use git-dir and work-tree when 生产,登台,开发网站和git repos在同一台服务器上:如何设置GIT_DIR和GIT_WORK_TREE - Production, Staging, Dev websites and git repos on same server: how to setup GIT_DIR and GIT_WORK_TREE 使用--git-dir和--work-tree选项时参数来源/主语含糊 - Ambiguous argument origin/master when using --git-dir and --work-tree options 通过--work-tree在别处获取git存储库的树,同时保持--git-dir存储库不被修改 - Obtain a git repository's tree elsewhere via --work-tree while keeping --git-dir repository unmodified 在TortoiseGIT上设置git-dir和git-work-tree - Setup git-dir and git-work-tree on TortoiseGIT 为什么 stash all 命令在命令行(Windows)中不起作用:git --git-dir=c/a.git --work-tree=c/b status -a? - Why stash all command won't work in command line (Windows): git --git-dir=c/a.git --work-tree=c/b status -a? 使用$ GIT_DIR环境变量或--git-dir标志在同一目录中运行多个git repos是个坏主意吗? - Is it a bad idea to run multiple git repos in the same directory using the $GIT_DIR environment variable or --git-dir flag?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM