12

以下に示すように、ベアリポジトリのワークツリーを設定する必要があります。

cd barerepo
git status
fatal: This operation must be run in a work tree

git --work-tree=/var/www/mywork/ status
# On branch master
nothing to commit (working directory clean)

そのリポジトリのワークツリーを設定して、毎回指定する必要がないようにするにはどうすればよいですか?

これで変更barerepo/configしてみましたが、うまくいきません。

[core]
    repositoryformatversion = 0
    filemode = true
    bare = true
    worktree = /var/www/mywork
4

3 に答える 3

16

ベア リポジトリにはワーク ツリーがあると想定されていないため、git は「fatal: core.bare and core.worktree do not make sense」というエラー メッセージを出力します。bare = falseしたがって、リポジトリの構成ファイルで設定する必要があります。

user@host:~$ cd barerepo
user@host:~/barerepo$ git config --bool core.bare false
user@host:~/barerepo$ git config --path core.worktree /var/www/mywork

ただし、barerepo が以前に存在しなかった場合は、代わりに次のコマンドを使用する必要があります。

git init --separate-git-dir=. /var/www/mywork

このコマンドは.git、作業ツリーに git dir を指すファイルも作成します。

gitdir: /home/user/barerepo
于 2012-08-08T02:34:07.320 に答える
3

提案されたソリューション (2012 年、2015 年 7 月にリリースされる Git 2.5 より前) は、コマンドでは直接動作しないgit configことに注意してください。
それは次のように死に続けます:

fatal: core.bare and core.worktree do not make sense.

これが Git 2.5 (2015 年 7 月) で対処される予定です。

Jeff King ( )によるcommit fada767 (2015 年 5 月 29 日)を参照してください。( 2015 年 6 月 16 日コミット 103b6f9Junio C Hamanoによってマージされました)peff
gitster

setup_git_directory: 遅延core.bare/core.worktreeエラー

core.bareとの両方core.worktreeが設定されている場合、偽の構成について不平を言い、終了します。
死ぬことは良いことです。なぜなら、コマンドが実行されて、潜在的に間違ったセットアップでダメージを与えることを避けるからです。しかし、作業ツリーを気にしないコマンドが実行できないことを意味するため、そこで
死ぬのは悪いことです。これにより、状況の修復が難しくなる可能性があります

  [setup]
  $ git config core.bare true
  $ git config core.worktree /some/path

  [OK, expected.]
  $ git status
  fatal: core.bare and core.worktree do not make sense

  [Hrm...]
  $ git config --unset core.worktree
  fatal: core.bare and core.worktree do not make sense

  [Nope...]
  $ git config --edit
  fatal: core.bare and core.worktree do not make sense

  [Gaaah.]
  $ git help config
  fatal: core.bare and core.worktree do not make sense

代わりに、偽の構成に気付いたときに (つまり、すべてのコマンドに対して) 警告を発行し、コマンドがワーク ツリーを使用しようとしたときにのみ停止します (setup_work_tree を呼び出すことによって)。

したがって、次のようになります。

$ git status
warning: core.bare and core.worktree do not make sense
fatal: unable to set up work tree using invalid config

$ git config --unset core.worktree
warning: core.bare and core.worktree do not make sense
于 2015-06-18T23:07:07.727 に答える