【问题标题】:Git error "fatal: GIT_WORK_TREE (or --work-tree=<directory>) not allowed without specifying GIT_DIR (or --git-dir=<directory>)"Git 错误“致命:在不指定 GIT_DIR(或 --git-dir=<directory>)的情况下不允许 GIT_WORK_TREE(或 --work-tree=<directory>)”
【发布时间】:2014-09-30 02:26:45
【问题描述】:

我将GIT_WORK_TREE 设置为.GIT_DIR 设置为.git。当我运行git init --bare 时,出现以下错误:

致命:GIT_WORK_TREE(或--work-tree=&lt;directory&gt;)在未指定GIT_DIR(或--git-dir=&lt;directory&gt;)的情况下不允许

那是怎么回事?我怀疑这可能与将GIT_DIR 设置为. 有关(如果它指向当前工作目录,它可能认为GIT_DIR 未设置?)。无论如何,让这个行为正常会很棒,这样我就不必每次想初始化 Git 存储库时都取消设置 GIT_WORK_TREE。

【问题讨论】:

标签: git environment-variables git-config git-init


【解决方案1】:

此错误消息来自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>)"),

所以在 Unbuntu 上,在执行 git init --bare 之前取消设置 GIT_WORK_TREE
见“Unset an environmental variable for a single command”:

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

我正在完美地在 Windows 上添加遥控器

git init --bare 不是“添加远程”,因此您需要检查触发该错误消息的命令。


在 Windows 上,使用 cmd /V/ /C as explained here:

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

【讨论】:

  • Windows 的答案是什么?
  • @irvnriir 我已经编辑了答案以添加 Windows 语法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-02
相关资源
最近更新 更多