命令: 此操作必须在工作树中运行

当我尝试更改分支时,会得到这个错误。

也许我会给一些信息的命令在

/path/to/git/repo/.

听命行事:

git branch

我得到了跟踪输出

* V1.5
V2.0
master

当我尝试命令

git checkout V2.0

我得到以下输出:

fatal: This operation must be run in a work tree

配置文件内容:

cat config
[core]
repositoryformatversion = 0
filemode = true
bare = true
[remote "origin"]
url = /path/to/git/repo/.git
259779 次浏览

You repository is bare, i.e. it does not have a working tree attached to it. You can clone it locally to create a working tree for it, or you could use one of several other options to tell Git where the working tree is, e.g. the --work-tree option for single commands, or the GIT_WORK_TREE environment variable. There is also the core.worktree configuration option but it will not work in a bare repository (check the man page for what it does).

# git --work-tree=/path/to/work/tree checkout master
# GIT_WORK_TREE=/path/to/work/tree git status