setting the work-tree of each bare repo

后端 未结 3 1202
醉梦人生
醉梦人生 2020-12-29 12:54

As you can see below I have to set the work-tree of a bare repo:

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

git --work-tree=/va         


        
3条回答
  •  -上瘾入骨i
    2020-12-29 13:22

    Note that the proposed solution (2012, pre Git 2.5 which will be released in July 2015) would not work directly with git config command.
    It would keep dying with a:

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

    That is what Git 2.5 (July 2015) will address:

    See commit fada767 (29 May 2015) by Jeff King (peff).
    (Merged by Junio C Hamano -- gitster -- in commit 103b6f9, 16 Jun 2015)

    setup_git_directory: delay core.bare/core.worktree errors

    If both core.bare and core.worktree are set, we complain about the bogus config and die.
    Dying is good, because it avoids commands running and doing damage in a potentially incorrect setup.
    But dying there is bad, because it means that commands which do not even care about the work tree cannot run.
    This can make repairing the situation harder:

      [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
    

    Instead, let's issue a warning about the bogus config when we notice it (i.e., for all commands), but only die when the command tries to use the work tree (by calling setup_work_tree).

    So we now get:

    $ 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
    

提交回复
热议问题